<math.h>
448 分钟阅读
类型
double_t
原址:https://zh.cppreference.com/w/c/numeric/math/float_t
作用:宽度至少等于 double 的最高效浮点类型 (typedef)
备注:
| |
float_t 和 double_t 类型分别是至少与 float 和 double 一样宽的浮点数类型,并满足 double_t 至少与 float_t 一样宽。FLT_EVAL_METHOD 的值确定 float_t 和 double_t 的类型。
FLT_EVAL_METHOD | 解释 |
|---|---|
0 | float_t 和 double_t 分别等价于 float 和 double |
1 | float_t 和 double_t 都等价于 double |
2 | float_t 和 double_t 都等价于 long double |
| 其他 | float_t 和 double_t 均为实现定义 |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
- 7.12 Mathematics <math.h> (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
- 7.12 Mathematics <math.h> (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12 Mathematics <math.h> (第 231 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12 Mathematics <math.h> (第 212 页)
参阅
| FLT_EVAL_METHOD (C99) | 指定所有算术运算以什么精度执行 (宏常量) |
|---|---|
float_t
原址:https://zh.cppreference.com/w/c/numeric/math/float_t
作用:宽度至少等于 float 的最高效浮点数类型 (typedef)
备注: line
枚举
宏
FP_FAST_FMA
原址:https://zh.cppreference.com/w/c/numeric/math/fma
作用:指示 fma 函数与操作数的一次乘法和一次加法相比,执行速度相当或更快 (宏常量)
备注:
| |
1-3) 计算 (x * y) + z,如同用无限精度,而仅舍入一次到结果类型。
4-6) 若定义宏常量 FP_FAST_FMA、FP_FAST_FMAF 或 FP_FAST_FMAL,则对应函数 fma、fmaf 或 fmal 分别求值快于(并且精度高于)double、float 和 long double 实参的表达式 x * y + z。若定义,则这些宏求值为整数 1。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 fmal。否则若任何实参拥有整数类型或 double 类型,则调用 fma。否则调用fmaf。
参数
| x, y, z | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 (x * y) + z 的值,如同计算为无限精度再舍入一次以适合目标类型(或者说是作为单次三元浮点数运算计算)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
x为零而
y为无穷大或
x为无穷大而
y为零,且
- 若
z非 NaN,则返回 NaN 并引发 FE_INVALID - 若
z为 NaN,则返回 NaN 并可能引发 FE_INVALID。
- 若
若
x * y为准确的无穷大且z为带相反符号的无穷大,则返回 NaN 并引发 FE_INVALID。若
x或y为 NaN,则返回 NaN。若
z为 NaN,且x * y不是0 * Inf或Inf * 0,则返回 NaN(而无 FE_INVALID)。
注解
此运算经常在硬件中实现为融合乘加 CPU 指令。若硬件支持,则期待定义相应的 FP_FAST_FMA* 宏,但多数实现即使在不定义这些宏时也利用该 CPU 指令。
POSIX 指定 x * y 非法且 z 为 NaN 的情形是定义域错误。
由于其无限的中间精度,fma 是其他正确舍入数学运算,如 sqrt 或甚至除法(在 CPU 不支持的平台上,例如 Itanium)的常用构建块。
同所有浮点数表达式,表达式 (x*y) + z 可编译为融合乘加,除非 #pragma STDC FP_CONTRACT 为关闭。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.13.1 The fma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.10.1 The fma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.13.1 The fma functions (第 188-189 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.10.1 The fma functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.13.1 The fma functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.10.1 The fma functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.13.1 The fma functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.10.1 The fma functions (第 466 页)
参阅
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
|---|---|
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fma 的 C++ 文档 |
FP_FAST_FMAF
原址:https://zh.cppreference.com/w/c/numeric/math/fma
作用:指示 fma 函数与操作数的一次乘法和一次加法相比,执行速度相当或更快 (宏常量)
备注:
| |
1-3) 计算 (x * y) + z,如同用无限精度,而仅舍入一次到结果类型。
4-6) 若定义宏常量 FP_FAST_FMA、FP_FAST_FMAF 或 FP_FAST_FMAL,则对应函数 fma、fmaf 或 fmal 分别求值快于(并且精度高于)double、float 和 long double 实参的表达式 x * y + z。若定义,则这些宏求值为整数 1。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 fmal。否则若任何实参拥有整数类型或 double 类型,则调用 fma。否则调用fmaf。
参数
| x, y, z | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 (x * y) + z 的值,如同计算为无限精度再舍入一次以适合目标类型(或者说是作为单次三元浮点数运算计算)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
x为零而
y为无穷大或
x为无穷大而
y为零,且
- 若
z非 NaN,则返回 NaN 并引发 FE_INVALID - 若
z为 NaN,则返回 NaN 并可能引发 FE_INVALID。
- 若
若
x * y为准确的无穷大且z为带相反符号的无穷大,则返回 NaN 并引发 FE_INVALID。若
x或y为 NaN,则返回 NaN。若
z为 NaN,且x * y不是0 * Inf或Inf * 0,则返回 NaN(而无 FE_INVALID)。
注解
此运算经常在硬件中实现为融合乘加 CPU 指令。若硬件支持,则期待定义相应的 FP_FAST_FMA* 宏,但多数实现即使在不定义这些宏时也利用该 CPU 指令。
POSIX 指定 x * y 非法且 z 为 NaN 的情形是定义域错误。
由于其无限的中间精度,fma 是其他正确舍入数学运算,如 sqrt 或甚至除法(在 CPU 不支持的平台上,例如 Itanium)的常用构建块。
同所有浮点数表达式,表达式 (x*y) + z 可编译为融合乘加,除非 #pragma STDC FP_CONTRACT 为关闭。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.13.1 The fma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.10.1 The fma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.13.1 The fma functions (第 188-189 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.10.1 The fma functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.13.1 The fma functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.10.1 The fma functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.13.1 The fma functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.10.1 The fma functions (第 466 页)
参阅
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
|---|---|
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fma 的 C++ 文档 |
FP_FAST_FMAL
原址:https://zh.cppreference.com/w/c/numeric/math/fma
作用:指示 fma 函数与操作数的一次乘法和一次加法相比,执行速度相当或更快 (宏常量)
备注:
| |
1-3) 计算 (x * y) + z,如同用无限精度,而仅舍入一次到结果类型。
4-6) 若定义宏常量 FP_FAST_FMA、FP_FAST_FMAF 或 FP_FAST_FMAL,则对应函数 fma、fmaf 或 fmal 分别求值快于(并且精度高于)double、float 和 long double 实参的表达式 x * y + z。若定义,则这些宏求值为整数 1。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 fmal。否则若任何实参拥有整数类型或 double 类型,则调用 fma。否则调用fmaf。
参数
| x, y, z | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 (x * y) + z 的值,如同计算为无限精度再舍入一次以适合目标类型(或者说是作为单次三元浮点数运算计算)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
x为零而
y为无穷大或
x为无穷大而
y为零,且
- 若
z非 NaN,则返回 NaN 并引发 FE_INVALID - 若
z为 NaN,则返回 NaN 并可能引发 FE_INVALID。
- 若
若
x * y为准确的无穷大且z为带相反符号的无穷大,则返回 NaN 并引发 FE_INVALID。若
x或y为 NaN,则返回 NaN。若
z为 NaN,且x * y不是0 * Inf或Inf * 0,则返回 NaN(而无 FE_INVALID)。
注解
此运算经常在硬件中实现为融合乘加 CPU 指令。若硬件支持,则期待定义相应的 FP_FAST_FMA* 宏,但多数实现即使在不定义这些宏时也利用该 CPU 指令。
POSIX 指定 x * y 非法且 z 为 NaN 的情形是定义域错误。
由于其无限的中间精度,fma 是其他正确舍入数学运算,如 sqrt 或甚至除法(在 CPU 不支持的平台上,例如 Itanium)的常用构建块。
同所有浮点数表达式,表达式 (x*y) + z 可编译为融合乘加,除非 #pragma STDC FP_CONTRACT 为关闭。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.13.1 The fma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.10.1 The fma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.13.1 The fma functions (第 188-189 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.10.1 The fma functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.13.1 The fma functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.10.1 The fma functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.13.1 The fma functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.10.1 The fma functions (第 466 页)
参阅
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
|---|---|
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fma 的 C++ 文档 |
FP_ILOGB0
原址:https://zh.cppreference.com/w/c/numeric/math/ilogb
作用:分别求值为当 x 为 0 或 NaN 时的 ilogb(x) (宏常量)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为有符号整数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ilogbl。否则,若 arg 拥有整数类型或 double 类型,则调用 ilogb。否则调用 ilogbf。
5) 展开成整数常量表达式,值为 INT_MIN 或 -[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
6) 展开成整数常量表达式,值为 INT_MIN 或 +[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
正式而言,无偏指数是非零 arg 的 logr|arg| 的整数部分,作为有符号整数,其中 r 是 FLT_RADIX。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为 int 值的 arg 的无偏指数。
若 arg 为零,则返回 FP_ILOGB0。
若 arg 为无穷大,则返回 INT_MAX。
若 arg 为 NaN,则返回 FP_ILOGBNAN。
若正确结果大于 INT_MAX 或小于 INT_MIN,则返回值未指定,且可能出现定义域或值域错误。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零、无穷大或 NaN ,则可能出现定义域错误或值域错误。
若正确结果大于 INT_MAX 或小于 INT_MIN ,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若正确结果大于 INT_MAX 或小于 INT_MIN,则引发 FE_INVALID。
- 若
arg为 ±0、 ±∞ 或 NaN,则引发 FE_INVALID。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)并且忽略当前舍入模式。
注解
若 arg 不是零、无穷大或 NaN,则返回的值准确等价于 (int)[logb](http://zh.cppreference.com/w/c/numeric/math/logb)(arg)。
POSIX 要求若 arg 为零、无穷大、NaN 或若正确结果在 int 的范围外则出现定义域错误。
POSIX 亦要求在 XSI 一致的系统上,正确结果大于 INT_MAX 时返回值为 INT_MAX,而正确结果小于 INT_MIN 时返回值为 INT_MIN。
在所有已知平台上正确结果都能表示成 int。对于要出现溢出的情况,INT_MAX 必须小于 [LDBL_MAX_EXP](http://zh.cppreference.com/w/c/types/limits) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits)) 或 INT_MIN 必须大于 [LDBL_MIN_EXP](http://zh.cppreference.com/w/c/types/limits) - [LDBL_MANT_DIG](http://zh.cppreference.com/w/c/types/limits)) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits))。
ilogb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 ilogb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/8 Mathematics <math.h> (第 232 页)
7.12.6.5 The ilogb functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.5 The ilogb functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12/8 Mathematics <math.h> (第 213 页)
7.12.6.5 The ilogb functions (第 224-225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.5 The ilogb functions (第 458 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ilogb 的 C++ 文档 |
FP_ILOGBNAN
原址:https://zh.cppreference.com/w/c/numeric/math/ilogb
作用:分别求值为当 x 为 0 或 NaN 时的 ilogb(x) (宏常量)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为有符号整数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ilogbl。否则,若 arg 拥有整数类型或 double 类型,则调用 ilogb。否则调用 ilogbf。
5) 展开成整数常量表达式,值为 INT_MIN 或 -[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
6) 展开成整数常量表达式,值为 INT_MIN 或 +[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
正式而言,无偏指数是非零 arg 的 logr|arg| 的整数部分,作为有符号整数,其中 r 是 FLT_RADIX。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为 int 值的 arg 的无偏指数。
若 arg 为零,则返回 FP_ILOGB0。
若 arg 为无穷大,则返回 INT_MAX。
若 arg 为 NaN,则返回 FP_ILOGBNAN。
若正确结果大于 INT_MAX 或小于 INT_MIN,则返回值未指定,且可能出现定义域或值域错误。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零、无穷大或 NaN ,则可能出现定义域错误或值域错误。
若正确结果大于 INT_MAX 或小于 INT_MIN ,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若正确结果大于 INT_MAX 或小于 INT_MIN,则引发 FE_INVALID。
- 若
arg为 ±0、 ±∞ 或 NaN,则引发 FE_INVALID。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)并且忽略当前舍入模式。
注解
若 arg 不是零、无穷大或 NaN,则返回的值准确等价于 (int)[logb](http://zh.cppreference.com/w/c/numeric/math/logb)(arg)。
POSIX 要求若 arg 为零、无穷大、NaN 或若正确结果在 int 的范围外则出现定义域错误。
POSIX 亦要求在 XSI 一致的系统上,正确结果大于 INT_MAX 时返回值为 INT_MAX,而正确结果小于 INT_MIN 时返回值为 INT_MIN。
在所有已知平台上正确结果都能表示成 int。对于要出现溢出的情况,INT_MAX 必须小于 [LDBL_MAX_EXP](http://zh.cppreference.com/w/c/types/limits) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits)) 或 INT_MIN 必须大于 [LDBL_MIN_EXP](http://zh.cppreference.com/w/c/types/limits) - [LDBL_MANT_DIG](http://zh.cppreference.com/w/c/types/limits)) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits))。
ilogb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 ilogb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/8 Mathematics <math.h> (第 232 页)
7.12.6.5 The ilogb functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.5 The ilogb functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12/8 Mathematics <math.h> (第 213 页)
7.12.6.5 The ilogb functions (第 224-225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.5 The ilogb functions (第 458 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ilogb 的 C++ 文档 |
FP_INFINITE
原址:https://zh.cppreference.com/w/c/numeric/math/FP_categories
作用:指示浮点数类别 (宏常量)
备注:
| |
FP_NORMAL、FP_SUBNORMAL、FP_ZERO、FP_INFINITE、FP_NAN 宏各代表一个独自的浮点数类别。它们都展开成整数常量表达式。
| 常量 | 解释 |
|---|---|
FP_NORMAL | 指示值为正规,即不是无穷大、非正规、非数或零 |
FP_SUBNORMAL | 指示值为非正规 |
FP_ZERO | 指示值为正或负零 |
FP_INFINITE | 指示值无法以底层类型表示(正或负无穷大) |
FP_NAN | 指示值是非数(NaN) |
示例
| |
输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
- 7.12/6 FP_NORMAL, … (第 169-170 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12/6 FP_NORMAL, … (第 232 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12/6 FP_NORMAL, … (第 213 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| FP_categories 的 C++ 文档 |
FP_NAN
原址:https://zh.cppreference.com/w/c/numeric/math/FP_categories
作用:指示浮点数类别 (宏常量)
备注:
| |
FP_NORMAL、FP_SUBNORMAL、FP_ZERO、FP_INFINITE、FP_NAN 宏各代表一个独自的浮点数类别。它们都展开成整数常量表达式。
| 常量 | 解释 |
|---|---|
FP_NORMAL | 指示值为正规,即不是无穷大、非正规、非数或零 |
FP_SUBNORMAL | 指示值为非正规 |
FP_ZERO | 指示值为正或负零 |
FP_INFINITE | 指示值无法以底层类型表示(正或负无穷大) |
FP_NAN | 指示值是非数(NaN) |
示例
| |
输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
- 7.12/6 FP_NORMAL, … (第 169-170 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12/6 FP_NORMAL, … (第 232 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12/6 FP_NORMAL, … (第 213 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| FP_categories 的 C++ 文档 |
FP_NORMAL
原址:https://zh.cppreference.com/w/c/numeric/math/FP_categories
作用:指示浮点数类别 (宏常量)
备注:
| |
FP_NORMAL、FP_SUBNORMAL、FP_ZERO、FP_INFINITE、FP_NAN 宏各代表一个独自的浮点数类别。它们都展开成整数常量表达式。
| 常量 | 解释 |
|---|---|
FP_NORMAL | 指示值为正规,即不是无穷大、非正规、非数或零 |
FP_SUBNORMAL | 指示值为非正规 |
FP_ZERO | 指示值为正或负零 |
FP_INFINITE | 指示值无法以底层类型表示(正或负无穷大) |
FP_NAN | 指示值是非数(NaN) |
示例
| |
输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
- 7.12/6 FP_NORMAL, … (第 169-170 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12/6 FP_NORMAL, … (第 232 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12/6 FP_NORMAL, … (第 213 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| FP_categories 的 C++ 文档 |
FP_SUBNORMAL
原址:https://zh.cppreference.com/w/c/numeric/math/FP_categories
作用:指示浮点数类别 (宏常量)
备注:
| |
FP_NORMAL、FP_SUBNORMAL、FP_ZERO、FP_INFINITE、FP_NAN 宏各代表一个独自的浮点数类别。它们都展开成整数常量表达式。
| 常量 | 解释 |
|---|---|
FP_NORMAL | 指示值为正规,即不是无穷大、非正规、非数或零 |
FP_SUBNORMAL | 指示值为非正规 |
FP_ZERO | 指示值为正或负零 |
FP_INFINITE | 指示值无法以底层类型表示(正或负无穷大) |
FP_NAN | 指示值是非数(NaN) |
示例
| |
输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
- 7.12/6 FP_NORMAL, … (第 169-170 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12/6 FP_NORMAL, … (第 232 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12/6 FP_NORMAL, … (第 213 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| FP_categories 的 C++ 文档 |
FP_ZERO
原址:https://zh.cppreference.com/w/c/numeric/math/FP_categories
作用:指示浮点数类别 (宏常量)
备注:
| |
FP_NORMAL、FP_SUBNORMAL、FP_ZERO、FP_INFINITE、FP_NAN 宏各代表一个独自的浮点数类别。它们都展开成整数常量表达式。
| 常量 | 解释 |
|---|---|
FP_NORMAL | 指示值为正规,即不是无穷大、非正规、非数或零 |
FP_SUBNORMAL | 指示值为非正规 |
FP_ZERO | 指示值为正或负零 |
FP_INFINITE | 指示值无法以底层类型表示(正或负无穷大) |
FP_NAN | 指示值是非数(NaN) |
示例
| |
输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
- 7.12/6 FP_NORMAL, … (第 169-170 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12/6 FP_NORMAL, … (第 232 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12/6 FP_NORMAL, … (第 213 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| FP_categories 的 C++ 文档 |
HUGE_VAL
原址:https://zh.cppreference.com/w/c/numeric/math/HUGE_VAL
作用:分别指示过大而无法以 float、double 和 long double 表示的值(无穷大) (宏常量)
备注:
| |
HUGE_VALF、HUGE_VAL 和 HUGE_VALL 宏展开成正浮点数常量表达式,它们比较等于上溢情况中浮点数函数和运算符的返回值(见 math_errhandling)。
| 常量 | 解释 |
|---|---|
HUGE_VALF | 展开成指示上溢的正 float 表达式 |
HUGE_VAL | 展开成指示上溢的正 double 表达式,不必可表示为 float |
HUGE_VALL | 展开成指示上溢的正 long double 表达式,不必可表示为 float 或 double |
在支持浮点数无穷大的平台上,这些宏始终分别展开成 float、double 和 long double 的正无穷大。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 231 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 517 页)
C99 标准(ISO/IEC 9899:1999):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 212 页)
F.9/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 454 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5 HUGE_VAL
参阅
| INFINITY (C99) | 求值为正无穷大或保证溢出 float 的值 (宏常量) |
|---|---|
| HUGE_VAL 的 C++ 文档 |
HUGE_VALF
原址:https://zh.cppreference.com/w/c/numeric/math/HUGE_VAL
作用:分别指示过大而无法以 float、double 和 long double 表示的值(无穷大) (宏常量)
备注:
| |
HUGE_VALF、HUGE_VAL 和 HUGE_VALL 宏展开成正浮点数常量表达式,它们比较等于上溢情况中浮点数函数和运算符的返回值(见 math_errhandling)。
| 常量 | 解释 |
|---|---|
HUGE_VALF | 展开成指示上溢的正 float 表达式 |
HUGE_VAL | 展开成指示上溢的正 double 表达式,不必可表示为 float |
HUGE_VALL | 展开成指示上溢的正 long double 表达式,不必可表示为 float 或 double |
在支持浮点数无穷大的平台上,这些宏始终分别展开成 float、double 和 long double 的正无穷大。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 231 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 517 页)
C99 标准(ISO/IEC 9899:1999):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 212 页)
F.9/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 454 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5 HUGE_VAL
参阅
| INFINITY (C99) | 求值为正无穷大或保证溢出 float 的值 (宏常量) |
|---|---|
| HUGE_VAL 的 C++ 文档 |
HUGE_VALL
原址:https://zh.cppreference.com/w/c/numeric/math/HUGE_VAL
作用:分别指示过大而无法以 float、double 和 long double 表示的值(无穷大) (宏常量)
备注:
| |
HUGE_VALF、HUGE_VAL 和 HUGE_VALL 宏展开成正浮点数常量表达式,它们比较等于上溢情况中浮点数函数和运算符的返回值(见 math_errhandling)。
| 常量 | 解释 |
|---|---|
HUGE_VALF | 展开成指示上溢的正 float 表达式 |
HUGE_VAL | 展开成指示上溢的正 double 表达式,不必可表示为 float |
HUGE_VALL | 展开成指示上溢的正 long double 表达式,不必可表示为 float 或 double |
在支持浮点数无穷大的平台上,这些宏始终分别展开成 float、double 和 long double 的正无穷大。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 231 页)
F.10/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 517 页)
C99 标准(ISO/IEC 9899:1999):
7.12/3 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 212 页)
F.9/2 HUGE_VAL, HUGE_VALF, HUGE_VALL (第 454 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5 HUGE_VAL
参阅
| INFINITY (C99) | 求值为正无穷大或保证溢出 float 的值 (宏常量) |
|---|---|
| HUGE_VAL 的 C++ 文档 |
INFINITY
原址:https://zh.cppreference.com/w/c/numeric/math/INFINITY
作用:求值为正无穷大或保证溢出 float 的值 (宏常量)
备注:
| |
若实现支持浮点数无穷大,则宏 INFINITY 展开成求值为正或无符号无穷大的 float 类型常量表达式。
若实现不支持浮点数无穷大,则宏 INFINITY 展开成保证在编译时上溢 float 的正值,而此宏的使用生成编译器警告。
用于打印无穷大的风格是实现定义的。
示例
显示用于打印无穷大的风格及其 IEEE 格式。
| |
可能的输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
- 7.12/4 INFINITY (第 231-232 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12/4 INFINITY (第 212-213 页)
参阅
| isinf (C99) | 检查给定数是否是无穷大 (宏函数) |
|---|---|
| HUGE_VALF (C99) HUGE_VAL (C99) HUGE_VALL | 分别指示过大而无法以 float、double 和 long double 表示的值(无穷大) (宏常量) |
| INFINITY 的 C++ 文档 |
MATH_ERREXCEPT
原址:https://zh.cppreference.com/w/c/numeric/math/math_errhandling
作用:定义用于常用数学函数的错误处理机制 (宏常量)
备注:
| |
宏常量 math_errhandling 展开成 int 类型的表达式,要么等于 MATH_ERRNO,要么等于 MATH_ERREXCEPT,要么等于其逐位或(MATH_ERRNO | MATH_ERREXCEPT)。
math_errhandling 的值指示浮点数运算符和函数所进行的错误处理:
| 常量 | 解释 |
|---|---|
MATH_ERREXCEPT | 指示使用浮点数异常:<fenv.h> 中至少定义了 FE_DIVBYZERO、FE_INVALID 及 FE_OVERFLOW。 |
MATH_ERRNO | 指明浮点数运算使用变量 errno 报告错误。 |
若实现支持 IEEE 浮点数算术(IEC 60559),则要求 math_errhandling & MATH_ERREXCEPT 非零。
识别下列浮点数错误条件:
| 条件 | 解释 | errno | 浮点数异常 | 示例 |
|---|---|---|---|---|
| 定义域错误 | 实参在该运算的数学上的定义域之外(每个函数的描述列出了要求的定义域错误) | EDOM | FE_INVALID | [acos](http://zh.cppreference.com/w/c/numeric/math/acos)(2) |
| 极点错误 | 函数的数学结果恰是无限大或未定义 | ERANGE | FE_DIVBYZERO | [log](http://zh.cppreference.com/w/c/numeric/math/log)(0.0)、1.0/0.0 |
| 上溢所致的值域错误 | 数学结果有限,但舍入后变为无限,或在向下舍入后变成最大可表示有限值 | ERANGE | FE_OVERFLOW | [pow](http://zh.cppreference.com/w/c/numeric/math/pow)([DBL_MAX](http://zh.cppreference.com/w/c/types/limits),2) |
| 下溢所致的值域错误 | 结果非零,但因为舍入变为零,或变成非正规并有精度损失 | ERANGE 或不改变(实现定义) | FE_UNDERFLOW 或无(实现定义) | DBL_TRUE_MIN/2 |
| 结果不准确 | 结果必须被舍入到目标类型 | 不改变 | FE_INEXACT或无(未指定) | [sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(2)、1.0/10.0 |
注意
通常,FE_INEXACT 是否为数学库函数所引发是未指定的,但这可以显式指定于函数的描述(例如 rint vs nearbyint)。
C99 前,浮点数异常是未指定的,要求对于任何定义于错误发生 [EDOM](http://zh.cppreference.com/w/c/error/errno_macros),要求对上溢和实现定义的下溢发生 [ERANGE](http://zh.cppreference.com/w/c/error/errno_macros)。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 170 页)
F.10/4 MATH_ERREXCEPT, math_errhandling (第 377 页)
C11 标准(ISO/IEC 9899:2011):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 233 页)
F.10/4 MATH_ERREXCEPT, math_errhandling (第 517 页)
C99 标准(ISO/IEC 9899:1999):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 214 页)
F.9/4 MATH_ERREXCEPT, math_errhandling> (第 454 页)
参阅
| FE_ALL_EXCEPT (C99) FE_DIVBYZERO (C99) FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW | 浮点数异常 (宏常量) |
|---|---|
| errno | 展开成 POSIX 兼容的线程局域错误编号变量 (宏变量) |
| math_errhandling 的 C++ 文档 |
MATH_ERRNO
原址:https://zh.cppreference.com/w/c/numeric/math/math_errhandling
作用:定义用于常用数学函数的错误处理机制 (宏常量)
备注:
| |
宏常量 math_errhandling 展开成 int 类型的表达式,要么等于 MATH_ERRNO,要么等于 MATH_ERREXCEPT,要么等于其逐位或(MATH_ERRNO | MATH_ERREXCEPT)。
math_errhandling 的值指示浮点数运算符和函数所进行的错误处理:
| 常量 | 解释 |
|---|---|
MATH_ERREXCEPT | 指示使用浮点数异常:<fenv.h> 中至少定义了 FE_DIVBYZERO、FE_INVALID 及 FE_OVERFLOW。 |
MATH_ERRNO | 指明浮点数运算使用变量 errno 报告错误。 |
若实现支持 IEEE 浮点数算术(IEC 60559),则要求 math_errhandling & MATH_ERREXCEPT 非零。
识别下列浮点数错误条件:
| 条件 | 解释 | errno | 浮点数异常 | 示例 |
|---|---|---|---|---|
| 定义域错误 | 实参在该运算的数学上的定义域之外(每个函数的描述列出了要求的定义域错误) | EDOM | FE_INVALID | [acos](http://zh.cppreference.com/w/c/numeric/math/acos)(2) |
| 极点错误 | 函数的数学结果恰是无限大或未定义 | ERANGE | FE_DIVBYZERO | [log](http://zh.cppreference.com/w/c/numeric/math/log)(0.0)、1.0/0.0 |
| 上溢所致的值域错误 | 数学结果有限,但舍入后变为无限,或在向下舍入后变成最大可表示有限值 | ERANGE | FE_OVERFLOW | [pow](http://zh.cppreference.com/w/c/numeric/math/pow)([DBL_MAX](http://zh.cppreference.com/w/c/types/limits),2) |
| 下溢所致的值域错误 | 结果非零,但因为舍入变为零,或变成非正规并有精度损失 | ERANGE 或不改变(实现定义) | FE_UNDERFLOW 或无(实现定义) | DBL_TRUE_MIN/2 |
| 结果不准确 | 结果必须被舍入到目标类型 | 不改变 | FE_INEXACT或无(未指定) | [sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(2)、1.0/10.0 |
注意
通常,FE_INEXACT 是否为数学库函数所引发是未指定的,但这可以显式指定于函数的描述(例如 rint vs nearbyint)。
C99 前,浮点数异常是未指定的,要求对于任何定义于错误发生 [EDOM](http://zh.cppreference.com/w/c/error/errno_macros),要求对上溢和实现定义的下溢发生 [ERANGE](http://zh.cppreference.com/w/c/error/errno_macros)。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 170 页)
F.10/4 MATH_ERREXCEPT, math_errhandling (第 377 页)
C11 标准(ISO/IEC 9899:2011):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 233 页)
F.10/4 MATH_ERREXCEPT, math_errhandling (第 517 页)
C99 标准(ISO/IEC 9899:1999):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 214 页)
F.9/4 MATH_ERREXCEPT, math_errhandling> (第 454 页)
参阅
| FE_ALL_EXCEPT (C99) FE_DIVBYZERO (C99) FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW | 浮点数异常 (宏常量) |
|---|---|
| errno | 展开成 POSIX 兼容的线程局域错误编号变量 (宏变量) |
| math_errhandling 的 C++ 文档 |
NAN
原址:https://zh.cppreference.com/w/c/numeric/math/NAN
作用:求值为 float 类型的安静 NaN (宏常量)
备注:
| |
宏 NAN 展开成求值为安静非数(QNaN)的 float 类型常量表达式。若实现不支持 QNaN,则不定义此宏。
用于打印 NaN 的风格是实现定义的。
注意
有许多不同的 NaN 值,区别于其载荷与其符号位。宏 NAN 所生成的 NaN 的载荷与符号位的内容是实现定义的。
示例
显示用于打印 NaN 的风格和 IEEE 格式。
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/5 NAN (第 TBD 页)
F.10/11/13 NAN (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/5 NAN (第 TBD 页)
F.10/11/13 NAN (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/5 NAN (第 232 页)
F.10/11/13 NAN (第 518 页)
C99 标准(ISO/IEC 9899:1999):
7.12/5 NAN (第 213 页)
F.9/11/13 NAN (第 455 页)
参阅
| nan (C99) nanf (C99) nanl (C99) | 返回 NaN(非数) (函数) |
|---|---|
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
| NAN 的 C++ 文档 |
__STDC_VERSION_MATH_H__
原址:
作用:
备注:
fpclassify
原址:https://zh.cppreference.com/w/c/numeric/math/fpclassify
作用:对给定的浮点数分类 (宏函数)
备注:
| |
归类浮点数 arg 到下列类别中:零、非正规、正规、无穷大、NaN 或实现定义类别。该宏返回整数。
忽略 FLT_EVAL_METHOD:即使以多于实参类型的范围和精度对它求值,首先仍将它转换到其语义类型,然后基于该类型分类:正规的 long double 值可能在转换到 double 时变为非正规,而在转换到 float 时变为零。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
指明 arg 类别的 FP_INFINITE、FP_NAN、FP_NORMAL、FP_SUBNORMAL、FP_ZERO 或实现定义类型之一。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
- 7.12.3.1 The fpclassify macro (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
- 7.12.3.1 The fpclassify macro (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12.3.1 The fpclassify macro (第 235 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.3.1 The fpclassify macro (第 216 页)
参阅
| isfinite (C99) | 检查给定数是否具有有限值 (宏函数) |
|---|---|
| isinf (C99) | 检查给定数是否是无穷大 (宏函数) |
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
| isnormal (C99) | 检查给定数是否正规 (宏函数) |
| fpclassify 的 C++ 文档 |
isfinite
原址:https://zh.cppreference.com/w/c/numeric/math/isfinite
作用:检查给定数是否具有有限值 (宏函数)
备注:
| |
确定给定的浮点数 arg 是否拥有有限值,即它是正规、非正规或零,但不是无穷大或 NaN。该宏返回整数。
忽略 FLT_EVAL_METHOD:即使以多于实参类型的范围和精度对它求值,首先仍将它转换到其语义类型,然后分类基于该类型。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若 arg 拥有有限值则返回非零整数,否则返回 0。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
- 7.12.3.2 The isfinite macro (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
- 7.12.3.2 The isfinite macro (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12.3.2 The isfinite macro (第 236 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.3.2 The isfinite macro (第 216-217 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| isinf (C99) | 检查给定数是否是无穷大 (宏函数) |
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
| isnormal (C99) | 检查给定数是否正规 (宏函数) |
| isfinite 的 C++ 文档 |
isgreater
原址:https://zh.cppreference.com/w/c/numeric/math/isgreater
作用:检查第一个浮点数实参是否大于第二个 (宏函数)
备注:
| |
确定浮点数 x 是否大于浮点数 y,而不设置浮点数异常。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若 x > y 则为非零整数,否则为 0。
注解
若一或两个参数为 NaN,则内建的 operator> 对浮点数可能引发 FE_INVALID。此宏是 operator> 的“安静”版本。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.14.1 The isgreater macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.14.1 The isgreater macro (第 189 页)
F.10.11 Comparison macros (第 386-387 页)
C11 标准(ISO/IEC 9899:2011):
7.12.14.1 The isgreater macro (第 259 页)
F.10.11 Comparison macros (第 531 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.14.1 The isgreater macro (第 240 页)
参阅
| isless (C99) | 检查第一个浮点数实参是否小于第二个 (宏函数) |
|---|---|
| isgreater 的 C++ 文档 |
isgreaterequal
原址:https://zh.cppreference.com/w/c/numeric/math/isgreaterequal
作用:检查第一个浮点数实参是否大于等于第二个 (宏函数)
备注:
| |
确定浮点数 x 是否大于或等于浮点数 y,而不设置浮点数异常。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若 x >= y 则为非零整数,否则为 0。
注解
若一或两个参数为 NaN,则内建的 operator>= 对浮点数可能引发 FE_INVALID。此宏是 operator>= 的“安静”版本。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.14.2 The isgreaterequal macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.14.2 The isgreaterequal macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.14.2 The isgreaterequal macro (第 259-260 页)
F.10.11 Comparison macros (第 531 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.14.2 The isgreaterequal macro (第 240-241 页)
参阅
| islessequal (C99) | 检查第一个浮点数实参是否小于或等于第二个 (宏函数) |
|---|---|
| isgreaterequal 的 C++ 文档 |
isinf
原址:https://zh.cppreference.com/w/c/numeric/math/isinf
作用:检查给定数是否是无穷大 (宏函数)
备注:
| |
确定给定的浮点数 arg 是否正或负无穷大。该宏返回整数。
忽略 FLT_EVAL_METHOD:即使以多于实参类型的范围和精度对它求值,首先仍将它转换到其语义类型,然后分类基于该类型。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若 arg 拥有无穷大值则为返回非零整数,否则返回 0 。
示例
| |
可能的输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
- 7.12.3.3 The isinf macro (第 236 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.3.3 The isinf macro (第 217 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| isfinite (C99) | 检查给定数是否具有有限值 (宏函数) |
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
| isnormal (C99) | 检查给定数是否正规 (宏函数) |
| isinf 的 C++ 文档 |
isless
原址:https://zh.cppreference.com/w/c/numeric/math/isless
作用:检查第一个浮点数实参是否小于第二个 (宏函数)
备注:
| |
确定浮点数 x 是否小于浮点数 y,而不设置浮点数异常。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若 x < y 则为非零整数,否则为 0。
注解
若一或两个实参为 NaN,则内建的 operator< 对浮点数可能引发 FE_INVALID。此宏是 operator< 的“安静”版本。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.14.3 The isless macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.14.3 The isless macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.14.3 The isless macro (第 260 页)
F.10.11 Comparison macros (第 531 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.14.3 The isless macro (第 241 页)
参阅
| isgreater (C99) | 检查第一个浮点数实参是否大于第二个 (宏函数) |
|---|---|
| isless 的 C++ 文档 |
islessequal
原址:https://zh.cppreference.com/w/c/numeric/math/islessequal
作用:检查第一个浮点数实参是否小于或等于第二个 (宏函数)
备注:
| |
确定浮点数 x 是否小于或等于浮点数 y,而不设置浮点数异常。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若 x <= y 则为非零整数,否则为 0。
注解
若一或两个实参为 NaN,则内建的 operator<= 对浮点数可能引发 FE_INVALID。此宏是 operator<= 的“安静”版本。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.14.4 The islessequal macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.14.4 The islessequal macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.14.4 The islessequal macro (第 260 页)
F.10.11 Comparison macros (第 531 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.14.4 The islessequal macro (第 241 页)
参阅
| isgreaterequal (C99) | 检查第一个浮点数实参是否大于等于第二个 (宏函数) |
|---|---|
| islessequal 的 C++ 文档 |
islessgreater
原址:https://zh.cppreference.com/w/c/numeric/math/islessgreater
作用:检查第一个浮点数实参是否小于或大于第二个 (宏函数)
备注:
| |
确定浮点数 x 是否小于或大于浮点数 y,而不设置浮点数异常。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若 x < y || x > y 则为非零整数,否则为 0 。
注解
若一或两个实参为 NaN,则内建的 operator< 和 operator> 可能对浮点数引发 FE_INVALID。此宏是表达式 x < y || x > y 的“安静”版本。宏不会对 x 和 y 求值两次。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.14.5 The islessgreater macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.14.5 The islessgreater macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.14.5 The islessgreater macro (第 261 页)
F.10.11 Comparison macros (第 531 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.14.5 The islessgreater macro (第 241-242 页)
参阅
| isless (C99) | 检查第一个浮点数实参是否小于第二个 (宏函数) |
|---|---|
| isgreater (C99) | 检查第一个浮点数实参是否大于第二个 (宏函数) |
| islessgreater 的 C++ 文档 |
isnan
原址:https://zh.cppreference.com/w/c/numeric/math/isnan
作用:检查给定数是否为 NaN (宏函数)
备注:
| |
确定给定的浮点数 arg 是否非数(NaN)值。该宏返回整数。
忽略 FLT_EVAL_METHOD:即使以多于实参类型的范围和精度对它求值,首先仍将它转换到其语义类型,然后分类基于该类型。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若 arg 为 NaN 则为非零整数,否则为 0。
注解
有多个拥有不同符号位和载荷的不同 NaN 值,参阅 nan。
NaN 值决不与自身或其他 NaN 值比较相等。复制 NaN 可能改变其位模式。
另一种测试浮点数是否 NaN 的方式是与自身比较:bool is_nan(double x) { return x != x; }。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
- 7.12.3.4 The isnan macro (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
- 7.12.3.4 The isnan macro (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12.3.4 The isnan macro (第 236-237 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.3.4 The isnan macro (第 217 页)
参阅
| nan (C99) nanf (C99) nanl (C99) | 返回 NaN(非数) (函数) |
|---|---|
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
| isfinite (C99) | 检查给定数是否具有有限值 (宏函数) |
| isinf (C99) | 检查给定数是否是无穷大 (宏函数) |
| isnormal (C99) | 检查给定数是否正规 (宏函数) |
| isunordered (C99) | 检查两个浮点数是否无序 (宏函数) |
| isnan 的 C++ 文档 |
isnormal
原址:https://zh.cppreference.com/w/c/numeric/math/isnormal
作用:检查给定数是否正规 (宏函数)
备注:
| |
确定给定的浮点数 arg 是否正规,即它不是零、非正规、无穷大或 NaN。该宏返回整数。
忽略 FLT_EVAL_METHOD:即使以多于实参类型的范围和精度对它求值,首先仍将它转换到其语义类型,然后分类基于该类型。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若 arg 正规则为非零整数,否则为 0。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
- 7.12.3.5 The isnormal macro (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
- 7.12.3.5 The isnormal macro (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12.3.5 The isnormal macro (第 237 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.3.5 The isnormal macro (第 217-218 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| isfinite (C99) | 检查给定数是否具有有限值 (宏函数) |
| isinf (C99) | 检查给定数是否是无穷大 (宏函数) |
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
| isnormal 的 C++ 文档 |
isunordered
原址:https://zh.cppreference.com/w/c/numeric/math/isunordered
作用:检查两个浮点数是否无序 (宏函数)
备注:
| |
确定浮点数 x 与 y 是否无序,即一或两个是 NaN,从而无法有意义地彼此比较。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若 x 或 y 为 NaN 则为非零整数,否则为 0。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.14.6 The isunordered macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.14.6 The isunordered macro (第 TBD 页)
F.10.11 Comparison macros (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.14.6 The isunordered macro (第 261 页)
F.10.11 Comparison macros (第 531 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.14.6 The isunordered macro (第 242 页)
参阅
| fpclassify (C99) | 对给定的浮点数分类 (宏函数) |
|---|---|
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
| isunordered 的 C++ 文档 |
math_errhandling
原址:https://zh.cppreference.com/w/c/numeric/math/math_errhandling
作用:定义用于常用数学函数的错误处理机制 (宏常量)
备注:
| |
宏常量 math_errhandling 展开成 int 类型的表达式,要么等于 MATH_ERRNO,要么等于 MATH_ERREXCEPT,要么等于其逐位或(MATH_ERRNO | MATH_ERREXCEPT)。
math_errhandling 的值指示浮点数运算符和函数所进行的错误处理:
| 常量 | 解释 |
|---|---|
MATH_ERREXCEPT | 指示使用浮点数异常:<fenv.h> 中至少定义了 FE_DIVBYZERO、FE_INVALID 及 FE_OVERFLOW。 |
MATH_ERRNO | 指明浮点数运算使用变量 errno 报告错误。 |
若实现支持 IEEE 浮点数算术(IEC 60559),则要求 math_errhandling & MATH_ERREXCEPT 非零。
识别下列浮点数错误条件:
| 条件 | 解释 | errno | 浮点数异常 | 示例 |
|---|---|---|---|---|
| 定义域错误 | 实参在该运算的数学上的定义域之外(每个函数的描述列出了要求的定义域错误) | EDOM | FE_INVALID | [acos](http://zh.cppreference.com/w/c/numeric/math/acos)(2) |
| 极点错误 | 函数的数学结果恰是无限大或未定义 | ERANGE | FE_DIVBYZERO | [log](http://zh.cppreference.com/w/c/numeric/math/log)(0.0)、1.0/0.0 |
| 上溢所致的值域错误 | 数学结果有限,但舍入后变为无限,或在向下舍入后变成最大可表示有限值 | ERANGE | FE_OVERFLOW | [pow](http://zh.cppreference.com/w/c/numeric/math/pow)([DBL_MAX](http://zh.cppreference.com/w/c/types/limits),2) |
| 下溢所致的值域错误 | 结果非零,但因为舍入变为零,或变成非正规并有精度损失 | ERANGE 或不改变(实现定义) | FE_UNDERFLOW 或无(实现定义) | DBL_TRUE_MIN/2 |
| 结果不准确 | 结果必须被舍入到目标类型 | 不改变 | FE_INEXACT或无(未指定) | [sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(2)、1.0/10.0 |
注意
通常,FE_INEXACT 是否为数学库函数所引发是未指定的,但这可以显式指定于函数的描述(例如 rint vs nearbyint)。
C99 前,浮点数异常是未指定的,要求对于任何定义于错误发生 [EDOM](http://zh.cppreference.com/w/c/error/errno_macros),要求对上溢和实现定义的下溢发生 [ERANGE](http://zh.cppreference.com/w/c/error/errno_macros)。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 170 页)
F.10/4 MATH_ERREXCEPT, math_errhandling (第 377 页)
C11 标准(ISO/IEC 9899:2011):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 233 页)
F.10/4 MATH_ERREXCEPT, math_errhandling (第 517 页)
C99 标准(ISO/IEC 9899:1999):
7.12/9 MATH_ERRNO, MATH_ERREXCEPT, math_errhandling (第 214 页)
F.9/4 MATH_ERREXCEPT, math_errhandling> (第 454 页)
参阅
| FE_ALL_EXCEPT (C99) FE_DIVBYZERO (C99) FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW | 浮点数异常 (宏常量) |
|---|---|
| errno | 展开成 POSIX 兼容的线程局域错误编号变量 (宏变量) |
| math_errhandling 的 C++ 文档 |
signbit
原址:https://zh.cppreference.com/w/c/numeric/math/signbit
作用:检查给定数是不是负数 (宏函数)
备注:
| |
确定给定的浮点数 arg 是否为负。该宏返回整数。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若 arg 为负,则返回非零整数,否则返回 0。
注解
此宏检测零、无穷大和 NaN 的符号。这个宏和 copysign 是检验 NaN 符号的唯二可移植方式。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
- 7.12.3.6 The signbit macro (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
- 7.12.3.6 The signbit macro (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
- 7.12.3.6 The signbit macro (第 237 页)
C99 标准(ISO/IEC 9899:1999):
- 7.12.3.6 The signbit macro (第 218 页)
参阅
| fabs fabsf (C99) fabsl (C99) | 计算浮点数的绝对值(|x||x|) (函数) |
|---|---|
| copysign (C99) copysignf (C99) copysignl (C99) | 从一个给定值的绝对值和另一个给定值的符号产生值 (函数) |
| signbit 的 C++ 文档 |
函数
acos
原址:https://zh.cppreference.com/w/c/numeric/math/acos
作用:计算反余弦({\small\arccos{x} }{\small\arccos{x} }arccos(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)余弦主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 acosl。否则,若实参拥有整数类型或 double 类型,则调用 acos。否则调用 acosf。若实参为复数,则宏调用对应的复数函数([cacosf](http://zh.cppreference.com/w/c/numeric/complex/cacos)、[cacos](http://zh.cppreference.com/w/c/numeric/complex/cacos)、[cacosl](http://zh.cppreference.com/w/c/numeric/complex/cacos))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 于范围 [0 ; π] 中的弧(反)余弦(arccos(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 在范围 [-1.0; 1.0] 外则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 +1,则返回值
+0。 - 若 |arg| > 1,则返回定义域错误并返回 NaN。
- 若实参 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.1 The acos functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.1 The acos functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.1 The acos functions (第 173 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.1 The acos functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.1 The acos functions (第 238 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.1 The acos functions (第 518 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.1 The acos functions (第 218 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.1 The acos functions (第 455 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.1 The acos function
参阅
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
|---|---|
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
| cacos (C99) cacosf (C99) cacosl (C99) | 计算复数反余弦 (函数) |
| acos 的 C++ 文档 |
acosf
原址:https://zh.cppreference.com/w/c/numeric/math/acos
作用:计算反余弦({\small\arccos{x} }{\small\arccos{x} }arccos(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)余弦主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 acosl。否则,若实参拥有整数类型或 double 类型,则调用 acos。否则调用 acosf。若实参为复数,则宏调用对应的复数函数([cacosf](http://zh.cppreference.com/w/c/numeric/complex/cacos)、[cacos](http://zh.cppreference.com/w/c/numeric/complex/cacos)、[cacosl](http://zh.cppreference.com/w/c/numeric/complex/cacos))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 于范围 [0 ; π] 中的弧(反)余弦(arccos(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 在范围 [-1.0; 1.0] 外则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 +1,则返回值
+0。 - 若 |arg| > 1,则返回定义域错误并返回 NaN。
- 若实参 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.1 The acos functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.1 The acos functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.1 The acos functions (第 173 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.1 The acos functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.1 The acos functions (第 238 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.1 The acos functions (第 518 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.1 The acos functions (第 218 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.1 The acos functions (第 455 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.1 The acos function
参阅
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
|---|---|
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
| cacos (C99) cacosf (C99) cacosl (C99) | 计算复数反余弦 (函数) |
| acos 的 C++ 文档 |
acosh
原址:https://zh.cppreference.com/w/c/numeric/math/acosh
作用:计算反双曲余弦({\small\operatorname{arcosh}{x} }{\small\operatorname{arcosh}{x} }arcosh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲余弦。
4) 泛型宏:若参数拥有 long double 类型,则调用 acoshl。否则,若参数拥有整数类型或 double 类型,则调用 acosh。否则调用 acoshf。若参数为复数,则宏调用对应的复数函数([cacoshf](http://zh.cppreference.com/w/c/numeric/complex/cacosh)、[cacosh](http://zh.cppreference.com/w/c/numeric/complex/cacosh)、[cacoshl](http://zh.cppreference.com/w/c/numeric/complex/cacosh))。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在区间 [0, +∞] 上的反双曲余弦(cosh-1
(arg) 或 arcosh(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
错误处理
报告 math_errhandling 中指定的错误。
若实参小于 1,则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参小于 1,则引发 FE_INVALID 并返回 NaN
- 若实参为 1,则返回 +0
- 若实参为 +∞,则返回 +∞
- 若实参为 NaN,则返回 NaN
注解
虽然 C 标准命名此函数为“弧双曲余弦”,但双曲函数的反函数仍是面积函数。其实参是双曲扇形的面积,而非弧长。正确的名称是“反双曲余弦”(POSIX 所用)或“面积双曲余弦”。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.1 The acosh functions (第 TBD 页)
7.27 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.1 The acosh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.1 The acosh functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.1 The acosh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.1 The acosh functions (第 240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.1 The acosh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.1 The acosh functions (第 221 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.1 The acosh functions (第 457 页)
参阅
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
|---|---|
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
| cacosh (C99) cacoshf (C99) cacoshl (C99) | 计算复数反双曲余弦 (函数) |
| acosh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲余弦”来自 MathWorld–A Wolfram Web Resource。
acoshf
原址:https://zh.cppreference.com/w/c/numeric/math/acosh
作用:计算反双曲余弦({\small\operatorname{arcosh}{x} }{\small\operatorname{arcosh}{x} }arcosh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲余弦。
4) 泛型宏:若参数拥有 long double 类型,则调用 acoshl。否则,若参数拥有整数类型或 double 类型,则调用 acosh。否则调用 acoshf。若参数为复数,则宏调用对应的复数函数([cacoshf](http://zh.cppreference.com/w/c/numeric/complex/cacosh)、[cacosh](http://zh.cppreference.com/w/c/numeric/complex/cacosh)、[cacoshl](http://zh.cppreference.com/w/c/numeric/complex/cacosh))。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在区间 [0, +∞] 上的反双曲余弦(cosh-1
(arg) 或 arcosh(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
错误处理
报告 math_errhandling 中指定的错误。
若实参小于 1,则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参小于 1,则引发 FE_INVALID 并返回 NaN
- 若实参为 1,则返回 +0
- 若实参为 +∞,则返回 +∞
- 若实参为 NaN,则返回 NaN
注解
虽然 C 标准命名此函数为“弧双曲余弦”,但双曲函数的反函数仍是面积函数。其实参是双曲扇形的面积,而非弧长。正确的名称是“反双曲余弦”(POSIX 所用)或“面积双曲余弦”。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.1 The acosh functions (第 TBD 页)
7.27 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.1 The acosh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.1 The acosh functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.1 The acosh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.1 The acosh functions (第 240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.1 The acosh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.1 The acosh functions (第 221 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.1 The acosh functions (第 457 页)
参阅
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
|---|---|
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
| cacosh (C99) cacoshf (C99) cacoshl (C99) | 计算复数反双曲余弦 (函数) |
| acosh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲余弦”来自 MathWorld–A Wolfram Web Resource。
acoshl
原址:https://zh.cppreference.com/w/c/numeric/math/acosh
作用:计算反双曲余弦({\small\operatorname{arcosh}{x} }{\small\operatorname{arcosh}{x} }arcosh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲余弦。
4) 泛型宏:若参数拥有 long double 类型,则调用 acoshl。否则,若参数拥有整数类型或 double 类型,则调用 acosh。否则调用 acoshf。若参数为复数,则宏调用对应的复数函数([cacoshf](http://zh.cppreference.com/w/c/numeric/complex/cacosh)、[cacosh](http://zh.cppreference.com/w/c/numeric/complex/cacosh)、[cacoshl](http://zh.cppreference.com/w/c/numeric/complex/cacosh))。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在区间 [0, +∞] 上的反双曲余弦(cosh-1
(arg) 或 arcosh(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
错误处理
报告 math_errhandling 中指定的错误。
若实参小于 1,则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参小于 1,则引发 FE_INVALID 并返回 NaN
- 若实参为 1,则返回 +0
- 若实参为 +∞,则返回 +∞
- 若实参为 NaN,则返回 NaN
注解
虽然 C 标准命名此函数为“弧双曲余弦”,但双曲函数的反函数仍是面积函数。其实参是双曲扇形的面积,而非弧长。正确的名称是“反双曲余弦”(POSIX 所用)或“面积双曲余弦”。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.1 The acosh functions (第 TBD 页)
7.27 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.1 The acosh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.1 The acosh functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.1 The acosh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.1 The acosh functions (第 240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.1 The acosh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.1 The acosh functions (第 221 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.1 The acosh functions (第 457 页)
参阅
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
|---|---|
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
| cacosh (C99) cacoshf (C99) cacoshl (C99) | 计算复数反双曲余弦 (函数) |
| acosh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲余弦”来自 MathWorld–A Wolfram Web Resource。
acosl
原址:https://zh.cppreference.com/w/c/numeric/math/acos
作用:计算反余弦({\small\arccos{x} }{\small\arccos{x} }arccos(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)余弦主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 acosl。否则,若实参拥有整数类型或 double 类型,则调用 acos。否则调用 acosf。若实参为复数,则宏调用对应的复数函数([cacosf](http://zh.cppreference.com/w/c/numeric/complex/cacos)、[cacos](http://zh.cppreference.com/w/c/numeric/complex/cacos)、[cacosl](http://zh.cppreference.com/w/c/numeric/complex/cacos))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 于范围 [0 ; π] 中的弧(反)余弦(arccos(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 在范围 [-1.0; 1.0] 外则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 +1,则返回值
+0。 - 若 |arg| > 1,则返回定义域错误并返回 NaN。
- 若实参 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.1 The acos functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.1 The acos functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.1 The acos functions (第 173 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.1 The acos functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.1 The acos functions (第 238 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.1 The acos functions (第 518 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.1 The acos functions (第 218 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.1 The acos functions (第 455 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.1 The acos function
参阅
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
|---|---|
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
| cacos (C99) cacosf (C99) cacosl (C99) | 计算复数反余弦 (函数) |
| acos 的 C++ 文档 |
asin
原址:https://zh.cppreference.com/w/c/numeric/math/asin
作用:计算反正弦({\small\arcsin{x} }{\small\arcsin{x} }arcsin(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)正弦主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3) asinl。否则,若实参拥有整数类型或 double 类型,则调用 (2) asin。否则调用 (1) asinf。若实参为复数,则宏调用对应的复数函数([casinf](http://zh.cppreference.com/w/c/numeric/complex/casin)、[casin](http://zh.cppreference.com/w/c/numeric/complex/casin)、[casinl](http://zh.cppreference.com/w/c/numeric/complex/casin))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在范围
[-
| π |
|---|
| 2 |
; +
| π |
|---|
| 2 |
]
中的弧(反)正弦(arcsin(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 在范围 [-1.0; 1.0] 外则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回未修改的实参。
- 若 |arg| > 1,则出现定义域错误并返回 NaN。
- 若实参为 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.2 The asin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.2 The asin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.2 The asin functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.2 The asin functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.2 The asin functions (第 238 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.2 The asin functions (第 518 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.2 The asin functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.2 The asin functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.2 The asin function
参阅
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
|---|---|
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
| casin (C99) casinf (C99) casinl (C99) | 计算复数反正弦 (函数) |
| asin 的 C++ 文档 |
asinf
原址:https://zh.cppreference.com/w/c/numeric/math/asin
作用:计算反正弦({\small\arcsin{x} }{\small\arcsin{x} }arcsin(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)正弦主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3) asinl。否则,若实参拥有整数类型或 double 类型,则调用 (2) asin。否则调用 (1) asinf。若实参为复数,则宏调用对应的复数函数([casinf](http://zh.cppreference.com/w/c/numeric/complex/casin)、[casin](http://zh.cppreference.com/w/c/numeric/complex/casin)、[casinl](http://zh.cppreference.com/w/c/numeric/complex/casin))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在范围
[-
| π |
|---|
| 2 |
; +
| π |
|---|
| 2 |
]
中的弧(反)正弦(arcsin(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 在范围 [-1.0; 1.0] 外则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回未修改的实参。
- 若 |arg| > 1,则出现定义域错误并返回 NaN。
- 若实参为 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.2 The asin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.2 The asin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.2 The asin functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.2 The asin functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.2 The asin functions (第 238 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.2 The asin functions (第 518 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.2 The asin functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.2 The asin functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.2 The asin function
参阅
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
|---|---|
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
| casin (C99) casinf (C99) casinl (C99) | 计算复数反正弦 (函数) |
| asin 的 C++ 文档 |
asinh
原址:https://zh.cppreference.com/w/c/numeric/math/asinh
作用:计算反双曲正弦({\small\operatorname{arsinh}{x} }{\small\operatorname{arsinh}{x} }arsinh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 asinhl。否则,若实参拥有整数类型或 double 类型,则调用 asinh。否则调用 asinhf。若实参为复数,则宏调用对应的复数函数(casinhf、casinh、casinhl)。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不发生错误,则返回 arg 的反双曲正弦(sinh-1
(arg) 或 arsinh(arg))。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0 或 ±∞,则返回不修改的参数
- 若参数为 NaN,则返回 NaN
注解
虽然 C 标准命名此函数为“弧双曲正弦”,但双曲函数的反函数仍是面积函数。其实参为双曲扇形的面积,而非弧长。正确的名称是“反双曲正弦”( POSIX 所用)或“面积双曲正弦”。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.2 The asinh functions (第 221 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.2 The asinh functions (第 457 页)
参阅
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
|---|---|
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
| casinh (C99) casinhf (C99) casinhl (C99) | 计算复数反双曲正弦 (函数) |
| asinh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲正弦”来自 MathWorld–A Wolfram Web Resource 。
asinhf
原址:https://zh.cppreference.com/w/c/numeric/math/asinh
作用:计算反双曲正弦({\small\operatorname{arsinh}{x} }{\small\operatorname{arsinh}{x} }arsinh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 asinhl。否则,若实参拥有整数类型或 double 类型,则调用 asinh。否则调用 asinhf。若实参为复数,则宏调用对应的复数函数(casinhf、casinh、casinhl)。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不发生错误,则返回 arg 的反双曲正弦(sinh-1
(arg) 或 arsinh(arg))。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0 或 ±∞,则返回不修改的参数
- 若参数为 NaN,则返回 NaN
注解
虽然 C 标准命名此函数为“弧双曲正弦”,但双曲函数的反函数仍是面积函数。其实参为双曲扇形的面积,而非弧长。正确的名称是“反双曲正弦”( POSIX 所用)或“面积双曲正弦”。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.2 The asinh functions (第 221 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.2 The asinh functions (第 457 页)
参阅
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
|---|---|
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
| casinh (C99) casinhf (C99) casinhl (C99) | 计算复数反双曲正弦 (函数) |
| asinh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲正弦”来自 MathWorld–A Wolfram Web Resource 。
asinhl
原址:https://zh.cppreference.com/w/c/numeric/math/asinh
作用:计算反双曲正弦({\small\operatorname{arsinh}{x} }{\small\operatorname{arsinh}{x} }arsinh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 asinhl。否则,若实参拥有整数类型或 double 类型,则调用 asinh。否则调用 asinhf。若实参为复数,则宏调用对应的复数函数(casinhf、casinh、casinhl)。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不发生错误,则返回 arg 的反双曲正弦(sinh-1
(arg) 或 arsinh(arg))。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0 或 ±∞,则返回不修改的参数
- 若参数为 NaN,则返回 NaN
注解
虽然 C 标准命名此函数为“弧双曲正弦”,但双曲函数的反函数仍是面积函数。其实参为双曲扇形的面积,而非弧长。正确的名称是“反双曲正弦”( POSIX 所用)或“面积双曲正弦”。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.2 The asinh functions (第 240-241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.2 The asinh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.2 The asinh functions (第 221 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.2 The asinh functions (第 457 页)
参阅
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
|---|---|
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
| casinh (C99) casinhf (C99) casinhl (C99) | 计算复数反双曲正弦 (函数) |
| asinh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲正弦”来自 MathWorld–A Wolfram Web Resource 。
asinl
原址:https://zh.cppreference.com/w/c/numeric/math/asin
作用:计算反正弦({\small\arcsin{x} }{\small\arcsin{x} }arcsin(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)正弦主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3) asinl。否则,若实参拥有整数类型或 double 类型,则调用 (2) asin。否则调用 (1) asinf。若实参为复数,则宏调用对应的复数函数([casinf](http://zh.cppreference.com/w/c/numeric/complex/casin)、[casin](http://zh.cppreference.com/w/c/numeric/complex/casin)、[casinl](http://zh.cppreference.com/w/c/numeric/complex/casin))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在范围
[-
| π |
|---|
| 2 |
; +
| π |
|---|
| 2 |
]
中的弧(反)正弦(arcsin(arg))。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 在范围 [-1.0; 1.0] 外则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回未修改的实参。
- 若 |arg| > 1,则出现定义域错误并返回 NaN。
- 若实参为 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.2 The asin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.2 The asin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.2 The asin functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.2 The asin functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.2 The asin functions (第 238 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.2 The asin functions (第 518 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.2 The asin functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.2 The asin functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.2 The asin function
参阅
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
|---|---|
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
| casin (C99) casinf (C99) casinl (C99) | 计算复数反正弦 (函数) |
| asin 的 C++ 文档 |
atan
原址:https://zh.cppreference.com/w/c/numeric/math/atan
作用:计算反正切({\small\arctan{x} }{\small\arctan{x} }arctan(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)正切主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3) atanl。否则,若实参拥有整数类型或 double 类型,则调用 (2) atan。否则调用 (1) atanf。若实参为复数,则宏调用对应的复数函数(catanf、catan、catanl)。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在
[-
| π |
|---|
| 2 |
; +
| π |
|---|
| 2 |
]
弧度范围中的弧(反)正切(arctan(arg))。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回不修改的参数
- 若参数为 +∞,则返回 +π/2
- 若参数为 -∞,则返回 -π/2
- 若参数为 NaN,则返回 NaN
注意
POSIX 指定在下溢情况下,返回不修改的 arg,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.3 The atan functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.3 The atan functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.3 The atan functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.3 The atan functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.3 The atan functions (第 238-239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.3 The atan functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.3 The atan functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.3 The atan functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.3 The atan function
参阅
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
|---|---|
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| catan (C99) catanf (C99) catanl (C99) | 计算复数反正切 (函数) |
| atan 的 C++ 文档 |
atan2
原址:https://zh.cppreference.com/w/c/numeric/math/atan2
作用:计算反正切,以符号确定象限 (函数)
备注:
| |
1-6) 计算 y / x 的弧(反)正切,以实参符号确定正确的象限。
7) 泛型宏:若任何参数拥有 long double 类型,则调用 atan2l。否则,若任何实参拥有整数类型或 double 类型,则调用 atan2。否则调用 atan2f。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 y/x 在 [-π ; +π] 弧度范围中的弧(反)正切(
arctan(
| y |
|---|
| x |
)
)。
Y 实参
返回值
X 实参
若出现定义域错误,则返回实现定义值。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 x 与 y 均为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术( IEC 60559 ),则
- 若
x与y均为零,则定义域错误不出现 - 若
x与y均为零,则也不出现值域错误 - 若
y为零,则不出现极点错误 - 若
y为±0且x为负或-0,则返回±π - 若
y为±0且x为正或+0,则返回±0 - 若
y为±∞且x有限,则返回±π/2 - 若
y为±∞且x为-∞,则返回±3π/4 - 若
y为±∞且x为+∞,则返回±π/4 - 若
x为±0且y为负,则返回-π/2 - 若
x为±0且y为正,则返回+π/2 - 若
x为-∞且y为正有限,则返回+π - 若
x为-∞且y为负有限,则返回-π - 若
x为+∞且y为正有限,则返回+0 - 若
x为+∞且y为负有限,则返回-0 - 若
x为 NaN 或y为 NaN,则返回 NaN
注意
atan2(y, x) 等价于 [carg](http://zh.cppreference.com/w/c/numeric/complex/carg)(x + I*y)。
POSIX 指定在下溢情况下,返回 y / x,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.4 The atan2 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.4 The atan2 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.4 The atan2 functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.4 The atan2 functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.4 The atan2 functions (第 239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.4 The atan2 functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.4 The atan2 functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.4 The atan2 functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.4 The atan2 function
参阅
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
|---|---|
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| carg (C99) cargf (C99) cargl (C99) | 计算复数的辐角 (函数) |
| atan2 的 C++ 文档 |
atan2f
原址:https://zh.cppreference.com/w/c/numeric/math/atan2
作用:计算反正切,以符号确定象限 (函数)
备注:
| |
1-6) 计算 y / x 的弧(反)正切,以实参符号确定正确的象限。
7) 泛型宏:若任何参数拥有 long double 类型,则调用 atan2l。否则,若任何实参拥有整数类型或 double 类型,则调用 atan2。否则调用 atan2f。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 y/x 在 [-π ; +π] 弧度范围中的弧(反)正切(
arctan(
| y |
|---|
| x |
)
)。
Y 实参
返回值
X 实参
若出现定义域错误,则返回实现定义值。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 x 与 y 均为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术( IEC 60559 ),则
- 若
x与y均为零,则定义域错误不出现 - 若
x与y均为零,则也不出现值域错误 - 若
y为零,则不出现极点错误 - 若
y为±0且x为负或-0,则返回±π - 若
y为±0且x为正或+0,则返回±0 - 若
y为±∞且x有限,则返回±π/2 - 若
y为±∞且x为-∞,则返回±3π/4 - 若
y为±∞且x为+∞,则返回±π/4 - 若
x为±0且y为负,则返回-π/2 - 若
x为±0且y为正,则返回+π/2 - 若
x为-∞且y为正有限,则返回+π - 若
x为-∞且y为负有限,则返回-π - 若
x为+∞且y为正有限,则返回+0 - 若
x为+∞且y为负有限,则返回-0 - 若
x为 NaN 或y为 NaN,则返回 NaN
注意
atan2(y, x) 等价于 [carg](http://zh.cppreference.com/w/c/numeric/complex/carg)(x + I*y)。
POSIX 指定在下溢情况下,返回 y / x,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.4 The atan2 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.4 The atan2 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.4 The atan2 functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.4 The atan2 functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.4 The atan2 functions (第 239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.4 The atan2 functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.4 The atan2 functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.4 The atan2 functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.4 The atan2 function
参阅
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
|---|---|
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| carg (C99) cargf (C99) cargl (C99) | 计算复数的辐角 (函数) |
| atan2 的 C++ 文档 |
atan2l
原址:https://zh.cppreference.com/w/c/numeric/math/atan2
作用:计算反正切,以符号确定象限 (函数)
备注:
| |
1-6) 计算 y / x 的弧(反)正切,以实参符号确定正确的象限。
7) 泛型宏:若任何参数拥有 long double 类型,则调用 atan2l。否则,若任何实参拥有整数类型或 double 类型,则调用 atan2。否则调用 atan2f。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 y/x 在 [-π ; +π] 弧度范围中的弧(反)正切(
arctan(
| y |
|---|
| x |
)
)。
Y 实参
返回值
X 实参
若出现定义域错误,则返回实现定义值。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 x 与 y 均为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术( IEC 60559 ),则
- 若
x与y均为零,则定义域错误不出现 - 若
x与y均为零,则也不出现值域错误 - 若
y为零,则不出现极点错误 - 若
y为±0且x为负或-0,则返回±π - 若
y为±0且x为正或+0,则返回±0 - 若
y为±∞且x有限,则返回±π/2 - 若
y为±∞且x为-∞,则返回±3π/4 - 若
y为±∞且x为+∞,则返回±π/4 - 若
x为±0且y为负,则返回-π/2 - 若
x为±0且y为正,则返回+π/2 - 若
x为-∞且y为正有限,则返回+π - 若
x为-∞且y为负有限,则返回-π - 若
x为+∞且y为正有限,则返回+0 - 若
x为+∞且y为负有限,则返回-0 - 若
x为 NaN 或y为 NaN,则返回 NaN
注意
atan2(y, x) 等价于 [carg](http://zh.cppreference.com/w/c/numeric/complex/carg)(x + I*y)。
POSIX 指定在下溢情况下,返回 y / x,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.4 The atan2 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.4 The atan2 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.4 The atan2 functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.4 The atan2 functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.4 The atan2 functions (第 239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.4 The atan2 functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.4 The atan2 functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.4 The atan2 functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.4 The atan2 function
参阅
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
|---|---|
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| carg (C99) cargf (C99) cargl (C99) | 计算复数的辐角 (函数) |
| atan2 的 C++ 文档 |
atanf
原址:https://zh.cppreference.com/w/c/numeric/math/atan
作用:计算反正切({\small\arctan{x} }{\small\arctan{x} }arctan(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)正切主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3) atanl。否则,若实参拥有整数类型或 double 类型,则调用 (2) atan。否则调用 (1) atanf。若实参为复数,则宏调用对应的复数函数(catanf、catan、catanl)。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在
[-
| π |
|---|
| 2 |
; +
| π |
|---|
| 2 |
]
弧度范围中的弧(反)正切(arctan(arg))。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回不修改的参数
- 若参数为 +∞,则返回 +π/2
- 若参数为 -∞,则返回 -π/2
- 若参数为 NaN,则返回 NaN
注意
POSIX 指定在下溢情况下,返回不修改的 arg,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.3 The atan functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.3 The atan functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.3 The atan functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.3 The atan functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.3 The atan functions (第 238-239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.3 The atan functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.3 The atan functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.3 The atan functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.3 The atan function
参阅
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
|---|---|
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| catan (C99) catanf (C99) catanl (C99) | 计算复数反正切 (函数) |
| atan 的 C++ 文档 |
atanh
原址:https://zh.cppreference.com/w/c/numeric/math/atanh
作用:计算反双曲正切({\small\operatorname{artanh}{x} }{\small\operatorname{artanh}{x} }artanh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲正切。
4) 泛型宏:若实参拥有 long double 类型,则调用 atanhl。否则,若实参拥有整数类型或 double 类型,则调用 atanh。否则调用 atanhf。若实参为复数,则调用对应的复函数(catanhf、catanh、catanhl)。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的反双曲正切(tanh-1
(arg) 或 artanh(arg))。
若出现定义域错误,则返回实现定义值(若支持则为 NaN)。
若出现极点错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL(带正确符号)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实参不在区间 [``-1``, ``+1``] 中,则出现值域错误。
若实参为 ±1,则出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回不修改的实参。
- 若实参为 ±1,则返回 ±∞ 并引发 FE_DIVBYZERO 。
- 若 |arg|>1,则返回 NaN 并引发 FE_INVALID。
- 若实参为 NaN,则返回 NaN 。
注意
虽然 C 标准命名此函数为“弧双曲正切”,但双曲函数的反函数是面积函数。其实参为双曲扇形的面积,而非弧。正确的名称为“反双曲正切”(POSIX 所用)或“面积双曲正切”。
POSIX 指定在下溢的情况下,返回不修改的 arg,而且若不支持,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.3 The atanh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.3 The atanh functions (第 520 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.3 The atanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.3 The atanh functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.3 The atanh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.3 The atanh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.3 The atanh functions (第 221-222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.3 The atanh functions (第 457 页)
参阅
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
|---|---|
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| catanh (C99) catanhf (C99) catanhl (C99) | 计算复数反双曲正切 (函数) |
| atanh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲正切。”来自 MathWorld–A Wolfram Web Resource。
atanhf
原址:https://zh.cppreference.com/w/c/numeric/math/atanh
作用:计算反双曲正切({\small\operatorname{artanh}{x} }{\small\operatorname{artanh}{x} }artanh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲正切。
4) 泛型宏:若实参拥有 long double 类型,则调用 atanhl。否则,若实参拥有整数类型或 double 类型,则调用 atanh。否则调用 atanhf。若实参为复数,则调用对应的复函数(catanhf、catanh、catanhl)。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的反双曲正切(tanh-1
(arg) 或 artanh(arg))。
若出现定义域错误,则返回实现定义值(若支持则为 NaN)。
若出现极点错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL(带正确符号)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实参不在区间 [``-1``, ``+1``] 中,则出现值域错误。
若实参为 ±1,则出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回不修改的实参。
- 若实参为 ±1,则返回 ±∞ 并引发 FE_DIVBYZERO 。
- 若 |arg|>1,则返回 NaN 并引发 FE_INVALID。
- 若实参为 NaN,则返回 NaN 。
注意
虽然 C 标准命名此函数为“弧双曲正切”,但双曲函数的反函数是面积函数。其实参为双曲扇形的面积,而非弧。正确的名称为“反双曲正切”(POSIX 所用)或“面积双曲正切”。
POSIX 指定在下溢的情况下,返回不修改的 arg,而且若不支持,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.3 The atanh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.3 The atanh functions (第 520 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.3 The atanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.3 The atanh functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.3 The atanh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.3 The atanh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.3 The atanh functions (第 221-222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.3 The atanh functions (第 457 页)
参阅
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
|---|---|
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| catanh (C99) catanhf (C99) catanhl (C99) | 计算复数反双曲正切 (函数) |
| atanh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲正切。”来自 MathWorld–A Wolfram Web Resource。
atanhl
原址:https://zh.cppreference.com/w/c/numeric/math/atanh
作用:计算反双曲正切({\small\operatorname{artanh}{x} }{\small\operatorname{artanh}{x} }artanh(x)) (函数)
备注:
| |
1-3) 计算 arg 的反双曲正切。
4) 泛型宏:若实参拥有 long double 类型,则调用 atanhl。否则,若实参拥有整数类型或 double 类型,则调用 atanh。否则调用 atanhf。若实参为复数,则调用对应的复函数(catanhf、catanh、catanhl)。
参数
| arg | - | 表示双曲扇形面积的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的反双曲正切(tanh-1
(arg) 或 artanh(arg))。
若出现定义域错误,则返回实现定义值(若支持则为 NaN)。
若出现极点错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL(带正确符号)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实参不在区间 [``-1``, ``+1``] 中,则出现值域错误。
若实参为 ±1,则出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回不修改的实参。
- 若实参为 ±1,则返回 ±∞ 并引发 FE_DIVBYZERO 。
- 若 |arg|>1,则返回 NaN 并引发 FE_INVALID。
- 若实参为 NaN,则返回 NaN 。
注意
虽然 C 标准命名此函数为“弧双曲正切”,但双曲函数的反函数是面积函数。其实参为双曲扇形的面积,而非弧。正确的名称为“反双曲正切”(POSIX 所用)或“面积双曲正切”。
POSIX 指定在下溢的情况下,返回不修改的 arg,而且若不支持,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.3 The atanh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.3 The atanh functions (第 520 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.3 The atanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.3 The atanh functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.3 The atanh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.3 The atanh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.3 The atanh functions (第 221-222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.3 The atanh functions (第 457 页)
参阅
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
|---|---|
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| catanh (C99) catanhf (C99) catanhl (C99) | 计算复数反双曲正切 (函数) |
| atanh 的 C++ 文档 |
外部链接
Weisstein, Eric W. “反双曲正切。”来自 MathWorld–A Wolfram Web Resource。
atanl
原址:https://zh.cppreference.com/w/c/numeric/math/atan
作用:计算反正切({\small\arctan{x} }{\small\arctan{x} }arctan(x)) (函数)
备注:
| |
1-6) 计算 arg 的弧(反)正切主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3) atanl。否则,若实参拥有整数类型或 double 类型,则调用 (2) atan。否则调用 (1) atanf。若实参为复数,则宏调用对应的复数函数(catanf、catan、catanl)。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 在
[-
| π |
|---|
| 2 |
; +
| π |
|---|
| 2 |
]
弧度范围中的弧(反)正切(arctan(arg))。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回不修改的参数
- 若参数为 +∞,则返回 +π/2
- 若参数为 -∞,则返回 -π/2
- 若参数为 NaN,则返回 NaN
注意
POSIX 指定在下溢情况下,返回不修改的 arg,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.3 The atan functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.3 The atan functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.3 The atan functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.3 The atan functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.3 The atan functions (第 238-239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.3 The atan functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.3 The atan functions (第 219 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.3 The atan functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.3 The atan function
参阅
| atan2 atan2f (C99) atan2l (C99) | 计算反正切,以符号确定象限 (函数) |
|---|---|
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| catan (C99) catanf (C99) catanl (C99) | 计算复数反正切 (函数) |
| atan 的 C++ 文档 |
cbrt
原址:https://zh.cppreference.com/w/c/numeric/math/cbrt
作用:计算立方根(\small{\sqrt[3]{x} }\small{\sqrt[3]{x} }3√x) (函数)
备注:
| |
1-3) 计算 arg 的立方根。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 cbrtl。否则,若 arg 拥有整数类型或 double 类型,则调用 cbrt。否则,调用 cbrtf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的立方根(3√argarg3)。
若出现下溢所致的错误,则返回(舍入后的)正确结果。
错误处理
报告 <ath_errhandlin> 中指定的错误。
若实现支持 IEEE 浮点数算术( IEC 60559 ),则
- 若参数为 ±0 或 ±∞ ,则返回不更改的参数
- 若参数为 NaN ,则返回 NaN 。
注解
cbrt(arg) 不等价于 [pow](http://zh.cppreference.com/w/c/numeric/math/pow)(arg, 1.0/3),因为有理数 1313 通常不等于 1.0/3 并且 pow 不能求负底数的小数次幂。另外 cbrt(arg) 常给出比 [pow](http://zh.cppreference.com/w/c/numeric/math/pow)(arg, 1.0/3) 更精确的结果(见示例)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.1 The cbrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.1 The cbrt functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.1 The cbrt functions (第 180-181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.1 The cbrt functions (第 381- 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.1 The cbrt functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.1 The cbrt functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.1 The cbrt functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.1 The cbrt functions (第 460 页)
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| cbrt 的 C++ 文档 |
cbrtf
原址:https://zh.cppreference.com/w/c/numeric/math/cbrt
作用:计算立方根(\small{\sqrt[3]{x} }\small{\sqrt[3]{x} }3√x) (函数)
备注:
| |
1-3) 计算 arg 的立方根。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 cbrtl。否则,若 arg 拥有整数类型或 double 类型,则调用 cbrt。否则,调用 cbrtf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的立方根(3√argarg3)。
若出现下溢所致的错误,则返回(舍入后的)正确结果。
错误处理
报告 <ath_errhandlin> 中指定的错误。
若实现支持 IEEE 浮点数算术( IEC 60559 ),则
- 若参数为 ±0 或 ±∞ ,则返回不更改的参数
- 若参数为 NaN ,则返回 NaN 。
注解
cbrt(arg) 不等价于 [pow](http://zh.cppreference.com/w/c/numeric/math/pow)(arg, 1.0/3),因为有理数 1313 通常不等于 1.0/3 并且 pow 不能求负底数的小数次幂。另外 cbrt(arg) 常给出比 [pow](http://zh.cppreference.com/w/c/numeric/math/pow)(arg, 1.0/3) 更精确的结果(见示例)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.1 The cbrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.1 The cbrt functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.1 The cbrt functions (第 180-181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.1 The cbrt functions (第 381- 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.1 The cbrt functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.1 The cbrt functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.1 The cbrt functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.1 The cbrt functions (第 460 页)
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| cbrt 的 C++ 文档 |
cbrtl
原址:https://zh.cppreference.com/w/c/numeric/math/cbrt
作用:计算立方根(\small{\sqrt[3]{x} }\small{\sqrt[3]{x} }3√x) (函数)
备注:
| |
1-3) 计算 arg 的立方根。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 cbrtl。否则,若 arg 拥有整数类型或 double 类型,则调用 cbrt。否则,调用 cbrtf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的立方根(3√argarg3)。
若出现下溢所致的错误,则返回(舍入后的)正确结果。
错误处理
报告 <ath_errhandlin> 中指定的错误。
若实现支持 IEEE 浮点数算术( IEC 60559 ),则
- 若参数为 ±0 或 ±∞ ,则返回不更改的参数
- 若参数为 NaN ,则返回 NaN 。
注解
cbrt(arg) 不等价于 [pow](http://zh.cppreference.com/w/c/numeric/math/pow)(arg, 1.0/3),因为有理数 1313 通常不等于 1.0/3 并且 pow 不能求负底数的小数次幂。另外 cbrt(arg) 常给出比 [pow](http://zh.cppreference.com/w/c/numeric/math/pow)(arg, 1.0/3) 更精确的结果(见示例)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.1 The cbrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.1 The cbrt functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.1 The cbrt functions (第 180-181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.1 The cbrt functions (第 381- 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.1 The cbrt functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.1 The cbrt functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.1 The cbrt functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.1 The cbrt functions (第 460 页)
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| cbrt 的 C++ 文档 |
ceil
原址:https://zh.cppreference.com/w/c/numeric/math/ceil
作用:计算不小于给定值的最小整数 (函数)
备注:
| |
1-3) 计算不小于 arg 的最小整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ceill。否则,若 arg 拥有整数类型或 double 类型,则调用 ceil。否则,调用 ceilf。
参数
| arg | - | 返回值 |
|---|---|---|
返回值
若不出现错误,则返回不小于 arg 的最小整数,即 ⌈arg⌉。
返回值
实参
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回它而不修改。 - 若
arg为 ±0,则返回它而不修改。 - 若
arg为 NaN,则返回 NaN。
注意
舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中的最大可表示浮点数都是准确的整数,故此函数自身决不上溢;然而存储于整数对象时,结果可以溢出任何整数类型(包含 intmax_t)。
此函数(double 实参的)表现如同(除了不引发 FE_INEXACT 的自由)实现如下
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.1 The ceil functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.1 The ceil functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.1 The ceil functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.1 The ceil functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.1 The ceil functions (第 251 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.1 The ceil functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.1 The ceil functions (第 231-232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.1 The ceil functions (第 462-463 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.1 The ceil function
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| rint (C99) rintf (C99) rintl (C99) lrint (C99) lrintf (C99) lrintl (C99) llrint (C99) llrintf (C99) llrintl (C99) | 使用当前舍入模式取整到整数,若结果有误则产生异常 (函数) |
| ceil 的 C++ 文档 |
ceilf
原址:https://zh.cppreference.com/w/c/numeric/math/ceil
作用:计算不小于给定值的最小整数 (函数)
备注:
| |
1-3) 计算不小于 arg 的最小整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ceill。否则,若 arg 拥有整数类型或 double 类型,则调用 ceil。否则,调用 ceilf。
参数
| arg | - | 返回值 |
|---|---|---|
返回值
若不出现错误,则返回不小于 arg 的最小整数,即 ⌈arg⌉。
返回值
实参
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回它而不修改。 - 若
arg为 ±0,则返回它而不修改。 - 若
arg为 NaN,则返回 NaN。
注意
舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中的最大可表示浮点数都是准确的整数,故此函数自身决不上溢;然而存储于整数对象时,结果可以溢出任何整数类型(包含 intmax_t)。
此函数(double 实参的)表现如同(除了不引发 FE_INEXACT 的自由)实现如下
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.1 The ceil functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.1 The ceil functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.1 The ceil functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.1 The ceil functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.1 The ceil functions (第 251 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.1 The ceil functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.1 The ceil functions (第 231-232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.1 The ceil functions (第 462-463 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.1 The ceil function
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| rint (C99) rintf (C99) rintl (C99) lrint (C99) lrintf (C99) lrintl (C99) llrint (C99) llrintf (C99) llrintl (C99) | 使用当前舍入模式取整到整数,若结果有误则产生异常 (函数) |
| ceil 的 C++ 文档 |
ceill
原址:https://zh.cppreference.com/w/c/numeric/math/ceil
作用:计算不小于给定值的最小整数 (函数)
备注:
| |
1-3) 计算不小于 arg 的最小整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ceill。否则,若 arg 拥有整数类型或 double 类型,则调用 ceil。否则,调用 ceilf。
参数
| arg | - | 返回值 |
|---|---|---|
返回值
若不出现错误,则返回不小于 arg 的最小整数,即 ⌈arg⌉。
返回值
实参
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回它而不修改。 - 若
arg为 ±0,则返回它而不修改。 - 若
arg为 NaN,则返回 NaN。
注意
舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中的最大可表示浮点数都是准确的整数,故此函数自身决不上溢;然而存储于整数对象时,结果可以溢出任何整数类型(包含 intmax_t)。
此函数(double 实参的)表现如同(除了不引发 FE_INEXACT 的自由)实现如下
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.1 The ceil functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.1 The ceil functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.1 The ceil functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.1 The ceil functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.1 The ceil functions (第 251 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.1 The ceil functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.1 The ceil functions (第 231-232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.1 The ceil functions (第 462-463 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.1 The ceil function
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| rint (C99) rintf (C99) rintl (C99) lrint (C99) lrintf (C99) lrintl (C99) llrint (C99) llrintf (C99) llrintl (C99) | 使用当前舍入模式取整到整数,若结果有误则产生异常 (函数) |
| ceil 的 C++ 文档 |
copysign
原址:https://zh.cppreference.com/w/c/numeric/math/copysign
作用:从一个给定值的绝对值和另一个给定值的符号产生值 (函数)
备注:
| |
1-3) 以 x 的绝对值和 y 的符号合成浮点数。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 copysignl。否则,若任何实参拥有整数类型或 double 类型,则调用 copysign。否则,调用 copysignf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回拥有 x 的绝对值和 y 的符号的浮点数。
若 x 为 NaN,则返回拥有 y 的符号的 NaN。
若 y 为 -0,则仅若实现支持与算术运算一致的有符号零,结果才为负。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 返回值是准确的(决不引发 FE_INEXACT),且与当前舍入模式独立。
注意
copysign 是操纵 NaN 值符号的唯一可移植方式(为检验 NaN 的符号,亦可用 signbit)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.1 The copysign functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.1 The copysign functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.1 The copysign functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.1 The copysign functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.1 The copysign functions (第 255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.1 The copysign functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.1 The copysign functions (第 236 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.1 The copysign functions (第 465 页)
参阅
| fabs fabsf (C99) fabsl (C99) | 计算浮点数的绝对值(|x||x|) (函数) |
|---|---|
| signbit (C99) | 检查给定数是不是负数 (宏函数) |
| copysign 的 C++ 文档 |
copysignf
原址:https://zh.cppreference.com/w/c/numeric/math/copysign
作用:从一个给定值的绝对值和另一个给定值的符号产生值 (函数)
备注:
| |
1-3) 以 x 的绝对值和 y 的符号合成浮点数。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 copysignl。否则,若任何实参拥有整数类型或 double 类型,则调用 copysign。否则,调用 copysignf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回拥有 x 的绝对值和 y 的符号的浮点数。
若 x 为 NaN,则返回拥有 y 的符号的 NaN。
若 y 为 -0,则仅若实现支持与算术运算一致的有符号零,结果才为负。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 返回值是准确的(决不引发 FE_INEXACT),且与当前舍入模式独立。
注意
copysign 是操纵 NaN 值符号的唯一可移植方式(为检验 NaN 的符号,亦可用 signbit)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.1 The copysign functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.1 The copysign functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.1 The copysign functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.1 The copysign functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.1 The copysign functions (第 255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.1 The copysign functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.1 The copysign functions (第 236 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.1 The copysign functions (第 465 页)
参阅
| fabs fabsf (C99) fabsl (C99) | 计算浮点数的绝对值(|x||x|) (函数) |
|---|---|
| signbit (C99) | 检查给定数是不是负数 (宏函数) |
| copysign 的 C++ 文档 |
copysignl
原址:https://zh.cppreference.com/w/c/numeric/math/copysign
作用:从一个给定值的绝对值和另一个给定值的符号产生值 (函数)
备注:
| |
1-3) 以 x 的绝对值和 y 的符号合成浮点数。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 copysignl。否则,若任何实参拥有整数类型或 double 类型,则调用 copysign。否则,调用 copysignf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回拥有 x 的绝对值和 y 的符号的浮点数。
若 x 为 NaN,则返回拥有 y 的符号的 NaN。
若 y 为 -0,则仅若实现支持与算术运算一致的有符号零,结果才为负。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 返回值是准确的(决不引发 FE_INEXACT),且与当前舍入模式独立。
注意
copysign 是操纵 NaN 值符号的唯一可移植方式(为检验 NaN 的符号,亦可用 signbit)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.1 The copysign functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.1 The copysign functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.1 The copysign functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.1 The copysign functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.1 The copysign functions (第 255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.1 The copysign functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.1 The copysign functions (第 236 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.1 The copysign functions (第 465 页)
参阅
| fabs fabsf (C99) fabsl (C99) | 计算浮点数的绝对值(|x||x|) (函数) |
|---|---|
| signbit (C99) | 检查给定数是不是负数 (宏函数) |
| copysign 的 C++ 文档 |
cos
原址:https://zh.cppreference.com/w/c/numeric/math/cos
作用:计算余弦({\small\cos{x} }{\small\cos{x} }cos(x)) (函数)
备注:
| |
1-6) 计算 arg (以弧度计量)的余弦。
7) 泛型宏:若实参拥有 long double 类型,则调用 cosl。否则,若实参拥有整数类型或 double 类型,则调用 cos。否则,调用 cosf、若实参为复数,则该宏调用对应的复函数([ccosf](http://zh.cppreference.com/w/c/numeric/complex/ccos)、[ccos](http://zh.cppreference.com/w/c/numeric/complex/ccos)、[ccosl](http://zh.cppreference.com/w/c/numeric/complex/ccos))。
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的余弦(cos(arg)),在范围 [-1 ; +1] 中。
若 arg 的绝对值很大,则结果可能只有少量或没有效数字。 (C99 前)
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确的结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 则若参数为 ±0,则结果为 1.0
- 若参数为 ±∞,则返回 NaN 并引发 FE_INVALID
- 若参数为 NaN,则返回 NaN
注意
参数为无穷大的情况不被指定为 C 中的定义域错误,但被定义为 POSIX 中的定义域错误。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.5 The cos functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.5 The cos functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.5 The cos functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.5 The cos functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.5 The cos functions (第 239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.5 The cos functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.5 The cos functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.5 The cos functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.5 The cos function
参阅
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
|---|---|
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| ccos (C99) ccosf (C99) ccosl (C99) | 计算复数余弦 (函数) |
| cos 的 C++ 文档 |
cosf
原址:https://zh.cppreference.com/w/c/numeric/math/cos
作用:计算余弦({\small\cos{x} }{\small\cos{x} }cos(x)) (函数)
备注:
| |
1-6) 计算 arg (以弧度计量)的余弦。
7) 泛型宏:若实参拥有 long double 类型,则调用 cosl。否则,若实参拥有整数类型或 double 类型,则调用 cos。否则,调用 cosf、若实参为复数,则该宏调用对应的复函数([ccosf](http://zh.cppreference.com/w/c/numeric/complex/ccos)、[ccos](http://zh.cppreference.com/w/c/numeric/complex/ccos)、[ccosl](http://zh.cppreference.com/w/c/numeric/complex/ccos))。
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的余弦(cos(arg)),在范围 [-1 ; +1] 中。
若 arg 的绝对值很大,则结果可能只有少量或没有效数字。 (C99 前)
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确的结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 则若参数为 ±0,则结果为 1.0
- 若参数为 ±∞,则返回 NaN 并引发 FE_INVALID
- 若参数为 NaN,则返回 NaN
注意
参数为无穷大的情况不被指定为 C 中的定义域错误,但被定义为 POSIX 中的定义域错误。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.5 The cos functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.5 The cos functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.5 The cos functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.5 The cos functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.5 The cos functions (第 239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.5 The cos functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.5 The cos functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.5 The cos functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.5 The cos function
参阅
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
|---|---|
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| ccos (C99) ccosf (C99) ccosl (C99) | 计算复数余弦 (函数) |
| cos 的 C++ 文档 |
cosh
原址:https://zh.cppreference.com/w/c/numeric/math/cosh
作用:计算双曲余弦({\small\cosh{x} }{\small\cosh{x} }cosh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲余弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 coshl。否则,若实参拥有整数类型或 double 类型,则调用 cosh。否则调用 coshf。若实参为复数,则宏调用对应的复数函数([ccoshf](http://zh.cppreference.com/w/c/numeric/complex/ccosh)、[ccosh](http://zh.cppreference.com/w/c/numeric/complex/ccosh)、[ccoshl](http://zh.cppreference.com/w/c/numeric/complex/ccosh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲余弦(cosh(arg) 或
| earg +e-arg |
|---|
| 2 |
)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 ±∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
对于 IEEE 兼容的 double 类型,若 |arg| > 710.5,则 cosh(arg) 上溢。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.4 The cosh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.4 The cosh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.4 The cosh functions (第 176 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.4 The cosh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.4 The cosh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.4 The cosh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.4 The cosh functions (第 222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.4 The cosh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.1 The cosh function
参阅
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
|---|---|
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
| ccosh (C99) ccoshf (C99) ccoshl (C99) | 计算复双曲余弦 (函数) |
| cosh 的 C++ 文档 |
coshf
原址:https://zh.cppreference.com/w/c/numeric/math/cosh
作用:计算双曲余弦({\small\cosh{x} }{\small\cosh{x} }cosh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲余弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 coshl。否则,若实参拥有整数类型或 double 类型,则调用 cosh。否则调用 coshf。若实参为复数,则宏调用对应的复数函数([ccoshf](http://zh.cppreference.com/w/c/numeric/complex/ccosh)、[ccosh](http://zh.cppreference.com/w/c/numeric/complex/ccosh)、[ccoshl](http://zh.cppreference.com/w/c/numeric/complex/ccosh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲余弦(cosh(arg) 或
| earg +e-arg |
|---|
| 2 |
)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 ±∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
对于 IEEE 兼容的 double 类型,若 |arg| > 710.5,则 cosh(arg) 上溢。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.4 The cosh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.4 The cosh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.4 The cosh functions (第 176 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.4 The cosh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.4 The cosh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.4 The cosh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.4 The cosh functions (第 222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.4 The cosh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.1 The cosh function
参阅
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
|---|---|
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
| ccosh (C99) ccoshf (C99) ccoshl (C99) | 计算复双曲余弦 (函数) |
| cosh 的 C++ 文档 |
coshl
原址:https://zh.cppreference.com/w/c/numeric/math/cosh
作用:计算双曲余弦({\small\cosh{x} }{\small\cosh{x} }cosh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲余弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 coshl。否则,若实参拥有整数类型或 double 类型,则调用 cosh。否则调用 coshf。若实参为复数,则宏调用对应的复数函数([ccoshf](http://zh.cppreference.com/w/c/numeric/complex/ccosh)、[ccosh](http://zh.cppreference.com/w/c/numeric/complex/ccosh)、[ccoshl](http://zh.cppreference.com/w/c/numeric/complex/ccosh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲余弦(cosh(arg) 或
| earg +e-arg |
|---|
| 2 |
)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 ±∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
对于 IEEE 兼容的 double 类型,若 |arg| > 710.5,则 cosh(arg) 上溢。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.4 The cosh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.4 The cosh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.4 The cosh functions (第 176 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.4 The cosh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.4 The cosh functions (第 241 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.4 The cosh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.4 The cosh functions (第 222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.4 The cosh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.1 The cosh function
参阅
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
|---|---|
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| acosh (C99) acoshf (C99) acoshl (C99) | 计算反双曲余弦(arcoshxarcoshx) (函数) |
| ccosh (C99) ccoshf (C99) ccoshl (C99) | 计算复双曲余弦 (函数) |
| cosh 的 C++ 文档 |
cosl
原址:https://zh.cppreference.com/w/c/numeric/math/cos
作用:计算余弦({\small\cos{x} }{\small\cos{x} }cos(x)) (函数)
备注:
| |
1-6) 计算 arg (以弧度计量)的余弦。
7) 泛型宏:若实参拥有 long double 类型,则调用 cosl。否则,若实参拥有整数类型或 double 类型,则调用 cos。否则,调用 cosf、若实参为复数,则该宏调用对应的复函数([ccosf](http://zh.cppreference.com/w/c/numeric/complex/ccos)、[ccos](http://zh.cppreference.com/w/c/numeric/complex/ccos)、[ccosl](http://zh.cppreference.com/w/c/numeric/complex/ccos))。
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的余弦(cos(arg)),在范围 [-1 ; +1] 中。
若 arg 的绝对值很大,则结果可能只有少量或没有效数字。 (C99 前)
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确的结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 则若参数为 ±0,则结果为 1.0
- 若参数为 ±∞,则返回 NaN 并引发 FE_INVALID
- 若参数为 NaN,则返回 NaN
注意
参数为无穷大的情况不被指定为 C 中的定义域错误,但被定义为 POSIX 中的定义域错误。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.5 The cos functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.5 The cos functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.5 The cos functions (第 174 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.5 The cos functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.5 The cos functions (第 239 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.5 The cos functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.5 The cos functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.5 The cos functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.5 The cos function
参阅
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
|---|---|
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| acos acosf (C99) acosl (C99) | 计算反余弦(arccosxarccosx) (函数) |
| ccos (C99) ccosf (C99) ccosl (C99) | 计算复数余弦 (函数) |
| cos 的 C++ 文档 |
erf
原址:https://zh.cppreference.com/w/c/numeric/math/erf
作用:计算误差函数 (函数)
备注:
| |
1-3) 计算 arg 的误差函数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 erfl。否则若 arg 拥有整数类型或 double 类型,则调用 erf。否则调用 erff。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的误差函数的值,即 2√π∫arg0e−t2dt2π∫0arge−t2dt。 若因下溢出现值域错误,则返回(舍入后的)正确结果,即 2⋅arg√π2⋅argπ。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±0
- 若参数为 ±∞,则返回 ±1
- 若参数为 NaN,则返回 NaN
注解
若 |arg| < [DBL_MIN](http://zh.cppreference.com/w/c/types/limits)*([sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(π)/2) 则保证下溢。
{\operatorname{erf}(\frac{x}{\sigma \sqrt{2} }){\operatorname{erf}(\frac{x}{\sigma \sqrt{2} }) 是测量结果小于与平均数相差 xx 的值的概率,其误差服从标准差为 σσ 的正态分布。
示例
| |
输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
7.12.8.1 The erf functions (第 249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.1 The erf functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.1 The erf functions (第 230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.1 The erf functions (第 462 页)
参阅
| erfc (C99) erfcf (C99) erfcl (C99) | 计算补误差函数 (函数) |
|---|---|
| erf 的 C++ 文档 |
外部链接
Weisstein, Eric W. “Erf.” From MathWorld–A Wolfram Web Resource。
erfc
原址:https://zh.cppreference.com/w/c/numeric/math/erfc
作用:计算补误差函数 (函数)
备注:
| |
1-3) 计算 arg 的补误差函数,即 1.0-erf(arg),但对于大的 arg 无精度损失。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 erfcl。否则,若 arg 拥有整数类型或 double 类型,则调用 erfc。否则,调用 erfcf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的补误差函数的值,即 2√π∫∞arge−t2dt2π∫arg∞e−t2dt 或 1−erf(arg)1−erf(arg)。
若出现源于下溢的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 +∞,则返回 +0
- 若参数为 -∞,则返回 2
- 若参数为 NaN,则返回 NaN
注解
对于 IEEE 兼容的 double 类型,若 arg > 26.55 则保证下溢。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.2 The erfc functions (第 230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.2 The erfc functions (第 462 页)
参阅
| erf (C99) erff (C99) erfl (C99) | 计算误差函数 (函数) |
|---|---|
| erfc 的 C++ 文档 |
外部链接
Weisstein, Eric W. “Erfc.” 来自 MathWorld–A Wolfram Web Resource。
erfcf
原址:https://zh.cppreference.com/w/c/numeric/math/erfc
作用:计算补误差函数 (函数)
备注:
| |
1-3) 计算 arg 的补误差函数,即 1.0-erf(arg),但对于大的 arg 无精度损失。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 erfcl。否则,若 arg 拥有整数类型或 double 类型,则调用 erfc。否则,调用 erfcf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的补误差函数的值,即 2√π∫∞arge−t2dt2π∫arg∞e−t2dt 或 1−erf(arg)1−erf(arg)。
若出现源于下溢的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 +∞,则返回 +0
- 若参数为 -∞,则返回 2
- 若参数为 NaN,则返回 NaN
注解
对于 IEEE 兼容的 double 类型,若 arg > 26.55 则保证下溢。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.2 The erfc functions (第 230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.2 The erfc functions (第 462 页)
参阅
| erf (C99) erff (C99) erfl (C99) | 计算误差函数 (函数) |
|---|---|
| erfc 的 C++ 文档 |
外部链接
Weisstein, Eric W. “Erfc.” 来自 MathWorld–A Wolfram Web Resource。
erfcl
原址:https://zh.cppreference.com/w/c/numeric/math/erfc
作用:计算补误差函数 (函数)
备注:
| |
1-3) 计算 arg 的补误差函数,即 1.0-erf(arg),但对于大的 arg 无精度损失。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 erfcl。否则,若 arg 拥有整数类型或 double 类型,则调用 erfc。否则,调用 erfcf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的补误差函数的值,即 2√π∫∞arge−t2dt2π∫arg∞e−t2dt 或 1−erf(arg)1−erf(arg)。
若出现源于下溢的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 +∞,则返回 +0
- 若参数为 -∞,则返回 2
- 若参数为 NaN,则返回 NaN
注解
对于 IEEE 兼容的 double 类型,若 arg > 26.55 则保证下溢。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.2 The erfc functions (第 249-250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.2 The erfc functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.2 The erfc functions (第 230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.2 The erfc functions (第 462 页)
参阅
| erf (C99) erff (C99) erfl (C99) | 计算误差函数 (函数) |
|---|---|
| erfc 的 C++ 文档 |
外部链接
Weisstein, Eric W. “Erfc.” 来自 MathWorld–A Wolfram Web Resource。
erff
原址:https://zh.cppreference.com/w/c/numeric/math/erf
作用:计算误差函数 (函数)
备注:
| |
1-3) 计算 arg 的误差函数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 erfl。否则若 arg 拥有整数类型或 double 类型,则调用 erf。否则调用 erff。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的误差函数的值,即 2√π∫arg0e−t2dt2π∫0arge−t2dt。 若因下溢出现值域错误,则返回(舍入后的)正确结果,即 2⋅arg√π2⋅argπ。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±0
- 若参数为 ±∞,则返回 ±1
- 若参数为 NaN,则返回 NaN
注解
若 |arg| < [DBL_MIN](http://zh.cppreference.com/w/c/types/limits)*([sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(π)/2) 则保证下溢。
{\operatorname{erf}(\frac{x}{\sigma \sqrt{2} }){\operatorname{erf}(\frac{x}{\sigma \sqrt{2} }) 是测量结果小于与平均数相差 xx 的值的概率,其误差服从标准差为 σσ 的正态分布。
示例
| |
输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
7.12.8.1 The erf functions (第 249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.1 The erf functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.1 The erf functions (第 230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.1 The erf functions (第 462 页)
参阅
| erfc (C99) erfcf (C99) erfcl (C99) | 计算补误差函数 (函数) |
|---|---|
| erf 的 C++ 文档 |
外部链接
Weisstein, Eric W. “Erf.” From MathWorld–A Wolfram Web Resource。
erfl
原址:https://zh.cppreference.com/w/c/numeric/math/erf
作用:计算误差函数 (函数)
备注:
| |
1-3) 计算 arg 的误差函数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 erfl。否则若 arg 拥有整数类型或 double 类型,则调用 erf。否则调用 erff。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的误差函数的值,即 2√π∫arg0e−t2dt2π∫0arge−t2dt。 若因下溢出现值域错误,则返回(舍入后的)正确结果,即 2⋅arg√π2⋅argπ。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±0
- 若参数为 ±∞,则返回 ±1
- 若参数为 NaN,则返回 NaN
注解
若 |arg| < [DBL_MIN](http://zh.cppreference.com/w/c/types/limits)*([sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(π)/2) 则保证下溢。
{\operatorname{erf}(\frac{x}{\sigma \sqrt{2} }){\operatorname{erf}(\frac{x}{\sigma \sqrt{2} }) 是测量结果小于与平均数相差 xx 的值的概率,其误差服从标准差为 σσ 的正态分布。
示例
| |
输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
7.12.8.1 The erf functions (第 249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.1 The erf functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.1 The erf functions (第 230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.1 The erf functions (第 462 页)
参阅
| erfc (C99) erfcf (C99) erfcl (C99) | 计算补误差函数 (函数) |
|---|---|
| erf 的 C++ 文档 |
外部链接
Weisstein, Eric W. “Erf.” From MathWorld–A Wolfram Web Resource。
exp
原址:https://zh.cppreference.com/w/c/numeric/math/exp
作用:计算 e 的给定次幂({\small e^x}{\small e^x}ex) (函数)
备注:
| |
1-3) 计算 e(欧拉数,2.7182818...)的 arg 次幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 expl。否则,若 arg 拥有整数类型或 double 类型,则调用 exp。否则调用 expf。若 arg 为复数或虚数,则宏调用对应的复数函数([cexpf](http://zh.cppreference.com/w/c/numeric/complex/cexp)、[cexp](http://zh.cppreference.com/w/c/numeric/complex/cexp)、[cexpl](http://zh.cppreference.com/w/c/numeric/complex/cexp))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的底 e 指数(*earg
*)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 -∞,则返回 +0
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
对于 IEEE 兼容的 double 类型,若 709.8 < arg 则保证上溢,而若 arg < -708.4 则保证下溢。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.1 The exp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.1 The exp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.1 The exp functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.1 The exp functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.1 The exp functions (第 242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.1 The exp functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.1 The exp functions (第 223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.1 The exp functions (第 458 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.1 The exp function
参阅
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
|---|---|
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
| cexp (C99) cexpf (C99) cexpl (C99) | 计算复数的 e 底指数 (函数) |
| exp 的 C++ 文档 |
exp2
原址:https://zh.cppreference.com/w/c/numeric/math/exp2
作用:计算 2 的给定次幂({\small 2^x}{\small 2^x}2x) (函数)
备注:
| |
1-3) 计算 2 的给定 n 次幂。
4) 泛型宏,若 n 拥有 long double 类型,则调用 exp2l。否则,若 n 用有整数类型或 double 类型,则调用 exp2。否则调用 exp2f。
参数
| n | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 n 的底 2 指数(*2n
*)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 -∞,则返回 +0
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.2 The exp2 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.2 The exp2 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.2 The exp2 functions (第 177 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.2 The exp2 functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.2 The exp2 functions (第 242-243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.2 The exp2 functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.2 The exp2 functions (第 223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.2 The exp2 functions (第 458 页)
参阅
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
|---|---|
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| exp2 的 C++ 文档 |
exp2f
原址:https://zh.cppreference.com/w/c/numeric/math/exp2
作用:计算 2 的给定次幂({\small 2^x}{\small 2^x}2x) (函数)
备注:
| |
1-3) 计算 2 的给定 n 次幂。
4) 泛型宏,若 n 拥有 long double 类型,则调用 exp2l。否则,若 n 用有整数类型或 double 类型,则调用 exp2。否则调用 exp2f。
参数
| n | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 n 的底 2 指数(*2n
*)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 -∞,则返回 +0
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.2 The exp2 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.2 The exp2 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.2 The exp2 functions (第 177 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.2 The exp2 functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.2 The exp2 functions (第 242-243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.2 The exp2 functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.2 The exp2 functions (第 223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.2 The exp2 functions (第 458 页)
参阅
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
|---|---|
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| exp2 的 C++ 文档 |
exp2l
原址:https://zh.cppreference.com/w/c/numeric/math/exp2
作用:计算 2 的给定次幂({\small 2^x}{\small 2^x}2x) (函数)
备注:
| |
1-3) 计算 2 的给定 n 次幂。
4) 泛型宏,若 n 拥有 long double 类型,则调用 exp2l。否则,若 n 用有整数类型或 double 类型,则调用 exp2。否则调用 exp2f。
参数
| n | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 n 的底 2 指数(*2n
*)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 -∞,则返回 +0
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.2 The exp2 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.2 The exp2 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.2 The exp2 functions (第 177 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.2 The exp2 functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.2 The exp2 functions (第 242-243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.2 The exp2 functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.2 The exp2 functions (第 223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.2 The exp2 functions (第 458 页)
参阅
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
|---|---|
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| exp2 的 C++ 文档 |
expf
原址:https://zh.cppreference.com/w/c/numeric/math/exp
作用:计算 e 的给定次幂({\small e^x}{\small e^x}ex) (函数)
备注:
| |
1-3) 计算 e(欧拉数,2.7182818...)的 arg 次幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 expl。否则,若 arg 拥有整数类型或 double 类型,则调用 exp。否则调用 expf。若 arg 为复数或虚数,则宏调用对应的复数函数([cexpf](http://zh.cppreference.com/w/c/numeric/complex/cexp)、[cexp](http://zh.cppreference.com/w/c/numeric/complex/cexp)、[cexpl](http://zh.cppreference.com/w/c/numeric/complex/cexp))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的底 e 指数(*earg
*)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 -∞,则返回 +0
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
对于 IEEE 兼容的 double 类型,若 709.8 < arg 则保证上溢,而若 arg < -708.4 则保证下溢。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.1 The exp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.1 The exp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.1 The exp functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.1 The exp functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.1 The exp functions (第 242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.1 The exp functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.1 The exp functions (第 223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.1 The exp functions (第 458 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.1 The exp function
参阅
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
|---|---|
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
| cexp (C99) cexpf (C99) cexpl (C99) | 计算复数的 e 底指数 (函数) |
| exp 的 C++ 文档 |
expl
原址:https://zh.cppreference.com/w/c/numeric/math/exp
作用:计算 e 的给定次幂({\small e^x}{\small e^x}ex) (函数)
备注:
| |
1-3) 计算 e(欧拉数,2.7182818...)的 arg 次幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 expl。否则,若 arg 拥有整数类型或 double 类型,则调用 exp。否则调用 expf。若 arg 为复数或虚数,则宏调用对应的复数函数([cexpf](http://zh.cppreference.com/w/c/numeric/complex/cexp)、[cexp](http://zh.cppreference.com/w/c/numeric/complex/cexp)、[cexpl](http://zh.cppreference.com/w/c/numeric/complex/cexp))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的底 e 指数(*earg
*)。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 1
- 若参数为 -∞,则返回 +0
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
对于 IEEE 兼容的 double 类型,若 709.8 < arg 则保证上溢,而若 arg < -708.4 则保证下溢。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.1 The exp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.1 The exp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.1 The exp functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.1 The exp functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.1 The exp functions (第 242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.1 The exp functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.1 The exp functions (第 223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.1 The exp functions (第 458 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.1 The exp function
参阅
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
|---|---|
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
| cexp (C99) cexpf (C99) cexpl (C99) | 计算复数的 e 底指数 (函数) |
| exp 的 C++ 文档 |
expm1
原址:https://zh.cppreference.com/w/c/numeric/math/expm1
作用:计算 e 的给定次幂减一({\small e^x-1}{\small e^x-1}ex-1) (函数)
备注:
| |
1-3) 计算 e(欧拉数,2.7182818)的给定 arg 次幂减 1.0。若 arg 接近零,则此函数比表达式 [exp](http://zh.cppreference.com/w/c/numeric/math/exp)(arg)-1.0 更精确。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 expm1l。否则,若 arg 拥有整数类型或 double 类型,则调用 expm1。否则调用 expm1f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误则返回 earg -1。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回不修改的参数
- 若参数为 -∞,则返回 -1
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
函数 expm1 和 log1p 对于金融计算有用:例如在计算小的日利率时:(1+x)n
-1 能表示为 expm1(n * [log1p](http://zh.cppreference.com/w/c/numeric/math/log1p)(x))。这些函数亦简化书写精确的反双曲函数。
对于 IEEE 兼容的 double 类型,若 709.8 < arg 则保证上溢。
注意
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.3 The expm1 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.3 The expm1 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.3 The expm1 functions (第 177 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.3 The expm1 functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.3 The expm1 functions (第 243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.3 The expm1 functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.3 The expm1 functions (第 223-224 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.3 The expm1 functions (第 458 页)
参阅
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
|---|---|
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| expm1 的 C++ 文档 |
expm1f
原址:https://zh.cppreference.com/w/c/numeric/math/expm1
作用:计算 e 的给定次幂减一({\small e^x-1}{\small e^x-1}ex-1) (函数)
备注:
| |
1-3) 计算 e(欧拉数,2.7182818)的给定 arg 次幂减 1.0。若 arg 接近零,则此函数比表达式 [exp](http://zh.cppreference.com/w/c/numeric/math/exp)(arg)-1.0 更精确。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 expm1l。否则,若 arg 拥有整数类型或 double 类型,则调用 expm1。否则调用 expm1f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误则返回 earg -1。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回不修改的参数
- 若参数为 -∞,则返回 -1
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
函数 expm1 和 log1p 对于金融计算有用:例如在计算小的日利率时:(1+x)n
-1 能表示为 expm1(n * [log1p](http://zh.cppreference.com/w/c/numeric/math/log1p)(x))。这些函数亦简化书写精确的反双曲函数。
对于 IEEE 兼容的 double 类型,若 709.8 < arg 则保证上溢。
注意
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.3 The expm1 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.3 The expm1 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.3 The expm1 functions (第 177 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.3 The expm1 functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.3 The expm1 functions (第 243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.3 The expm1 functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.3 The expm1 functions (第 223-224 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.3 The expm1 functions (第 458 页)
参阅
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
|---|---|
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| expm1 的 C++ 文档 |
expm1l
原址:https://zh.cppreference.com/w/c/numeric/math/expm1
作用:计算 e 的给定次幂减一({\small e^x-1}{\small e^x-1}ex-1) (函数)
备注:
| |
1-3) 计算 e(欧拉数,2.7182818)的给定 arg 次幂减 1.0。若 arg 接近零,则此函数比表达式 [exp](http://zh.cppreference.com/w/c/numeric/math/exp)(arg)-1.0 更精确。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 expm1l。否则,若 arg 拥有整数类型或 double 类型,则调用 expm1。否则调用 expm1f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误则返回 earg -1。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回不修改的参数
- 若参数为 -∞,则返回 -1
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注意
函数 expm1 和 log1p 对于金融计算有用:例如在计算小的日利率时:(1+x)n
-1 能表示为 expm1(n * [log1p](http://zh.cppreference.com/w/c/numeric/math/log1p)(x))。这些函数亦简化书写精确的反双曲函数。
对于 IEEE 兼容的 double 类型,若 709.8 < arg 则保证上溢。
注意
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.3 The expm1 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.3 The expm1 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.3 The expm1 functions (第 177 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.3 The expm1 functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.3 The expm1 functions (第 243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.3 The expm1 functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.3 The expm1 functions (第 223-224 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.3 The expm1 functions (第 458 页)
参阅
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
|---|---|
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| expm1 的 C++ 文档 |
fabs
原址:https://zh.cppreference.com/w/c/numeric/math/fabs
作用:计算浮点数的绝对值(|x|\small{|x|}|x|) (函数)
备注:
| |
1-6) 计算浮点数 arg 的绝对值。
当且仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)才声明带有十进制浮点数形参的函数。 (C23 起)
7) 泛型宏:若实参拥有 _Decimal128、_Decimal64、_Decimal32、(C23 起)long double、double 或 float 类型,则分别调用 fabsd128、fabsd64、fabsd32、(C23 起)fabsl、fabs 或 fabsf。否则若实参拥有整数类型,则调用 fabs。否则若实参为复数,则宏调用对应的复函数(cabsf、cabs、cabsl)。否则行为未定义。
参数
| arg | - | 浮点数 |
|---|---|---|
| arith | - | 浮点数或整数 |
返回值
若成功,则返回 arg 的绝对值(|arg||arg|)。值是准确的,且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 <ath_errhandlin> 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 +0。
- 若参数为 ±∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.2 The fabs functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.2 The fabs functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.2 The fabs functions (第 181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.2 The fabs functions (第 382 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.2 The fabs functions (第 248 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.2 The fabs functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.2 The fabs functions (第 228-229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.2 The fabs functions (第 460 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.2 The fabs function
参阅
| abs labs llabs (C99) | 计算整数的绝对值(|x||x|) (函数) |
|---|---|
| copysign (C99) copysignf (C99) copysignl (C99) | 从一个给定值的绝对值和另一个给定值的符号产生值 (函数) |
| signbit (C99) | 检查给定数是不是负数 (宏函数) |
| cabs (C99) cabsf (C99) cabsl (C99) | 计算复数的模(绝对值) (函数) |
| fabs 的 C++ 文档 |
fabsf
原址:https://zh.cppreference.com/w/c/numeric/math/fabs
作用:计算浮点数的绝对值(|x|\small{|x|}|x|) (函数)
备注:
| |
1-6) 计算浮点数 arg 的绝对值。
当且仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)才声明带有十进制浮点数形参的函数。 (C23 起)
7) 泛型宏:若实参拥有 _Decimal128、_Decimal64、_Decimal32、(C23 起)long double、double 或 float 类型,则分别调用 fabsd128、fabsd64、fabsd32、(C23 起)fabsl、fabs 或 fabsf。否则若实参拥有整数类型,则调用 fabs。否则若实参为复数,则宏调用对应的复函数(cabsf、cabs、cabsl)。否则行为未定义。
参数
| arg | - | 浮点数 |
|---|---|---|
| arith | - | 浮点数或整数 |
返回值
若成功,则返回 arg 的绝对值(|arg||arg|)。值是准确的,且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 <ath_errhandlin> 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 +0。
- 若参数为 ±∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.2 The fabs functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.2 The fabs functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.2 The fabs functions (第 181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.2 The fabs functions (第 382 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.2 The fabs functions (第 248 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.2 The fabs functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.2 The fabs functions (第 228-229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.2 The fabs functions (第 460 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.2 The fabs function
参阅
| abs labs llabs (C99) | 计算整数的绝对值(|x||x|) (函数) |
|---|---|
| copysign (C99) copysignf (C99) copysignl (C99) | 从一个给定值的绝对值和另一个给定值的符号产生值 (函数) |
| signbit (C99) | 检查给定数是不是负数 (宏函数) |
| cabs (C99) cabsf (C99) cabsl (C99) | 计算复数的模(绝对值) (函数) |
| fabs 的 C++ 文档 |
fabsl
原址:https://zh.cppreference.com/w/c/numeric/math/fabs
作用:计算浮点数的绝对值(|x|\small{|x|}|x|) (函数)
备注:
| |
1-6) 计算浮点数 arg 的绝对值。
当且仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)才声明带有十进制浮点数形参的函数。 (C23 起)
7) 泛型宏:若实参拥有 _Decimal128、_Decimal64、_Decimal32、(C23 起)long double、double 或 float 类型,则分别调用 fabsd128、fabsd64、fabsd32、(C23 起)fabsl、fabs 或 fabsf。否则若实参拥有整数类型,则调用 fabs。否则若实参为复数,则宏调用对应的复函数(cabsf、cabs、cabsl)。否则行为未定义。
参数
| arg | - | 浮点数 |
|---|---|---|
| arith | - | 浮点数或整数 |
返回值
若成功,则返回 arg 的绝对值(|arg||arg|)。值是准确的,且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 <ath_errhandlin> 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 +0。
- 若参数为 ±∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.2 The fabs functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.2 The fabs functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.2 The fabs functions (第 181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.2 The fabs functions (第 382 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.2 The fabs functions (第 248 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.2 The fabs functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.2 The fabs functions (第 228-229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.2 The fabs functions (第 460 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.2 The fabs function
参阅
| abs labs llabs (C99) | 计算整数的绝对值(|x||x|) (函数) |
|---|---|
| copysign (C99) copysignf (C99) copysignl (C99) | 从一个给定值的绝对值和另一个给定值的符号产生值 (函数) |
| signbit (C99) | 检查给定数是不是负数 (宏函数) |
| cabs (C99) cabsf (C99) cabsl (C99) | 计算复数的模(绝对值) (函数) |
| fabs 的 C++ 文档 |
fdim
原址:https://zh.cppreference.com/w/c/numeric/math/fdim
作用:确定两个浮点数的非负数差(max{\small\max{(0, x-y)} }max(0, x-y)) (函数)
备注:
| |
1-3) 返回 x 与 y 间的正差,即若 x>y 则返回 x-y,否则(若 x≤y)返回 +0。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 fdiml。否则,若任何实参拥有整数类型或 double 类型,则调用 fdim。否则调用 fdimf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 x 与 y 间的正差。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若任一实参为 NaN,则返回 NaN。
注意
等价于 [fmax](http://zh.cppreference.com/w/c/numeric/math/fmax)(x-y, 0),除了 NaN 处理要求。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.1 The fdim functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.1 The fdim functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.1 The fdim functions (第 187-188 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.9.1 The fdim functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.1 The fdim functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.1 The fdim functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.1 The fdim functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.1 The fdim functions (第 466 页)
参阅
| abs labs llabs (C99) | 计算整数的绝对值(|x||x|) (函数) |
|---|---|
| fmax (C99) fmaxf (C99) fmaxl (C99) | 确定两个浮点数的较大者 (函数) |
| fdim 的 C++ 文档 |
fdimf
原址:https://zh.cppreference.com/w/c/numeric/math/fdim
作用:确定两个浮点数的非负数差(max{\small\max{(0, x-y)} }max(0, x-y)) (函数)
备注:
| |
1-3) 返回 x 与 y 间的正差,即若 x>y 则返回 x-y,否则(若 x≤y)返回 +0。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 fdiml。否则,若任何实参拥有整数类型或 double 类型,则调用 fdim。否则调用 fdimf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 x 与 y 间的正差。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若任一实参为 NaN,则返回 NaN。
注意
等价于 [fmax](http://zh.cppreference.com/w/c/numeric/math/fmax)(x-y, 0),除了 NaN 处理要求。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.1 The fdim functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.1 The fdim functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.1 The fdim functions (第 187-188 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.9.1 The fdim functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.1 The fdim functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.1 The fdim functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.1 The fdim functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.1 The fdim functions (第 466 页)
参阅
| abs labs llabs (C99) | 计算整数的绝对值(|x||x|) (函数) |
|---|---|
| fmax (C99) fmaxf (C99) fmaxl (C99) | 确定两个浮点数的较大者 (函数) |
| fdim 的 C++ 文档 |
fdiml
原址:https://zh.cppreference.com/w/c/numeric/math/fdim
作用:确定两个浮点数的非负数差(max{\small\max{(0, x-y)} }max(0, x-y)) (函数)
备注:
| |
1-3) 返回 x 与 y 间的正差,即若 x>y 则返回 x-y,否则(若 x≤y)返回 +0。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 fdiml。否则,若任何实参拥有整数类型或 double 类型,则调用 fdim。否则调用 fdimf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 x 与 y 间的正差。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若任一实参为 NaN,则返回 NaN。
注意
等价于 [fmax](http://zh.cppreference.com/w/c/numeric/math/fmax)(x-y, 0),除了 NaN 处理要求。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.1 The fdim functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.1 The fdim functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.1 The fdim functions (第 187-188 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.9.1 The fdim functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.1 The fdim functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.1 The fdim functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.1 The fdim functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.1 The fdim functions (第 466 页)
参阅
| abs labs llabs (C99) | 计算整数的绝对值(|x||x|) (函数) |
|---|---|
| fmax (C99) fmaxf (C99) fmaxl (C99) | 确定两个浮点数的较大者 (函数) |
| fdim 的 C++ 文档 |
floor
原址:https://zh.cppreference.com/w/c/numeric/math/floor
作用:计算不大于给定值的最大整数 (函数)
备注:
| |
1-3) 计算不大于 arg 的最大整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 floorl。否则,若 arg 用有整数类型或 double 类型,则调用 floor。否则调用 floorf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回不大于 arg 的最大整数,即 ⌊arg⌋。
返回值
参数
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入方式无效。
- 若
arg为 ±∞,则返回不修改的参数。 - 若
arg为 ±0,则返回不修改的参数。 - 若
arg为 NaN,则返回 NaN。
注解
在舍入非整数有限值时可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数准确地为整数,故此函数自身决不上溢;然而存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.2 The floor functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.2 The floor functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.2 The floor functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.2 The floor functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.2 The floor functions (第 251 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.2 The floor functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.2 The floor functions (第 232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.2 The floor functions (第 463 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.3 The floor function
参阅
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
|---|---|
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| floor 的 C++ 文档 |
floorf
原址:https://zh.cppreference.com/w/c/numeric/math/floor
作用:计算不大于给定值的最大整数 (函数)
备注:
| |
1-3) 计算不大于 arg 的最大整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 floorl。否则,若 arg 用有整数类型或 double 类型,则调用 floor。否则调用 floorf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回不大于 arg 的最大整数,即 ⌊arg⌋。
返回值
参数
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入方式无效。
- 若
arg为 ±∞,则返回不修改的参数。 - 若
arg为 ±0,则返回不修改的参数。 - 若
arg为 NaN,则返回 NaN。
注解
在舍入非整数有限值时可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数准确地为整数,故此函数自身决不上溢;然而存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.2 The floor functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.2 The floor functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.2 The floor functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.2 The floor functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.2 The floor functions (第 251 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.2 The floor functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.2 The floor functions (第 232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.2 The floor functions (第 463 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.3 The floor function
参阅
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
|---|---|
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| floor 的 C++ 文档 |
floorl
原址:https://zh.cppreference.com/w/c/numeric/math/floor
作用:计算不大于给定值的最大整数 (函数)
备注:
| |
1-3) 计算不大于 arg 的最大整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 floorl。否则,若 arg 用有整数类型或 double 类型,则调用 floor。否则调用 floorf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回不大于 arg 的最大整数,即 ⌊arg⌋。
返回值
参数
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入方式无效。
- 若
arg为 ±∞,则返回不修改的参数。 - 若
arg为 ±0,则返回不修改的参数。 - 若
arg为 NaN,则返回 NaN。
注解
在舍入非整数有限值时可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数准确地为整数,故此函数自身决不上溢;然而存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.2 The floor functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.2 The floor functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.2 The floor functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.2 The floor functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.2 The floor functions (第 251 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.2 The floor functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.2 The floor functions (第 232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.2 The floor functions (第 463 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.3 The floor function
参阅
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
|---|---|
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| floor 的 C++ 文档 |
fma
原址:https://zh.cppreference.com/w/c/numeric/math/fma
作用:计算结合的乘加运算 (函数)
备注:
| |
1-3) 计算 (x * y) + z,如同用无限精度,而仅舍入一次到结果类型。
4-6) 若定义宏常量 FP_FAST_FMA、FP_FAST_FMAF 或 FP_FAST_FMAL,则对应函数 fma、fmaf 或 fmal 分别求值快于(并且精度高于)double、float 和 long double 实参的表达式 x * y + z。若定义,则这些宏求值为整数 1。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 fmal。否则若任何实参拥有整数类型或 double 类型,则调用 fma。否则调用fmaf。
参数
| x, y, z | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 (x * y) + z 的值,如同计算为无限精度再舍入一次以适合目标类型(或者说是作为单次三元浮点数运算计算)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
x为零而
y为无穷大或
x为无穷大而
y为零,且
- 若
z非 NaN,则返回 NaN 并引发 FE_INVALID - 若
z为 NaN,则返回 NaN 并可能引发 FE_INVALID。
- 若
若
x * y为准确的无穷大且z为带相反符号的无穷大,则返回 NaN 并引发 FE_INVALID。若
x或y为 NaN,则返回 NaN。若
z为 NaN,且x * y不是0 * Inf或Inf * 0,则返回 NaN(而无 FE_INVALID)。
注解
此运算经常在硬件中实现为融合乘加 CPU 指令。若硬件支持,则期待定义相应的 FP_FAST_FMA* 宏,但多数实现即使在不定义这些宏时也利用该 CPU 指令。
POSIX 指定 x * y 非法且 z 为 NaN 的情形是定义域错误。
由于其无限的中间精度,fma 是其他正确舍入数学运算,如 sqrt 或甚至除法(在 CPU 不支持的平台上,例如 Itanium)的常用构建块。
同所有浮点数表达式,表达式 (x*y) + z 可编译为融合乘加,除非 #pragma STDC FP_CONTRACT 为关闭。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.13.1 The fma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.10.1 The fma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.13.1 The fma functions (第 188-189 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.10.1 The fma functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.13.1 The fma functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.10.1 The fma functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.13.1 The fma functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.10.1 The fma functions (第 466 页)
参阅
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
|---|---|
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fma 的 C++ 文档 |
fmaf
原址:https://zh.cppreference.com/w/c/numeric/math/fma
作用:计算结合的乘加运算 (函数)
备注:
| |
1-3) 计算 (x * y) + z,如同用无限精度,而仅舍入一次到结果类型。
4-6) 若定义宏常量 FP_FAST_FMA、FP_FAST_FMAF 或 FP_FAST_FMAL,则对应函数 fma、fmaf 或 fmal 分别求值快于(并且精度高于)double、float 和 long double 实参的表达式 x * y + z。若定义,则这些宏求值为整数 1。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 fmal。否则若任何实参拥有整数类型或 double 类型,则调用 fma。否则调用fmaf。
参数
| x, y, z | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 (x * y) + z 的值,如同计算为无限精度再舍入一次以适合目标类型(或者说是作为单次三元浮点数运算计算)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
x为零而
y为无穷大或
x为无穷大而
y为零,且
- 若
z非 NaN,则返回 NaN 并引发 FE_INVALID - 若
z为 NaN,则返回 NaN 并可能引发 FE_INVALID。
- 若
若
x * y为准确的无穷大且z为带相反符号的无穷大,则返回 NaN 并引发 FE_INVALID。若
x或y为 NaN,则返回 NaN。若
z为 NaN,且x * y不是0 * Inf或Inf * 0,则返回 NaN(而无 FE_INVALID)。
注解
此运算经常在硬件中实现为融合乘加 CPU 指令。若硬件支持,则期待定义相应的 FP_FAST_FMA* 宏,但多数实现即使在不定义这些宏时也利用该 CPU 指令。
POSIX 指定 x * y 非法且 z 为 NaN 的情形是定义域错误。
由于其无限的中间精度,fma 是其他正确舍入数学运算,如 sqrt 或甚至除法(在 CPU 不支持的平台上,例如 Itanium)的常用构建块。
同所有浮点数表达式,表达式 (x*y) + z 可编译为融合乘加,除非 #pragma STDC FP_CONTRACT 为关闭。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.13.1 The fma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.10.1 The fma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.13.1 The fma functions (第 188-189 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.10.1 The fma functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.13.1 The fma functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.10.1 The fma functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.13.1 The fma functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.10.1 The fma functions (第 466 页)
参阅
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
|---|---|
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fma 的 C++ 文档 |
fmal
原址:https://zh.cppreference.com/w/c/numeric/math/fma
作用:计算结合的乘加运算 (函数)
备注:
| |
1-3) 计算 (x * y) + z,如同用无限精度,而仅舍入一次到结果类型。
4-6) 若定义宏常量 FP_FAST_FMA、FP_FAST_FMAF 或 FP_FAST_FMAL,则对应函数 fma、fmaf 或 fmal 分别求值快于(并且精度高于)double、float 和 long double 实参的表达式 x * y + z。若定义,则这些宏求值为整数 1。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 fmal。否则若任何实参拥有整数类型或 double 类型,则调用 fma。否则调用fmaf。
参数
| x, y, z | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回 (x * y) + z 的值,如同计算为无限精度再舍入一次以适合目标类型(或者说是作为单次三元浮点数运算计算)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
x为零而
y为无穷大或
x为无穷大而
y为零,且
- 若
z非 NaN,则返回 NaN 并引发 FE_INVALID - 若
z为 NaN,则返回 NaN 并可能引发 FE_INVALID。
- 若
若
x * y为准确的无穷大且z为带相反符号的无穷大,则返回 NaN 并引发 FE_INVALID。若
x或y为 NaN,则返回 NaN。若
z为 NaN,且x * y不是0 * Inf或Inf * 0,则返回 NaN(而无 FE_INVALID)。
注解
此运算经常在硬件中实现为融合乘加 CPU 指令。若硬件支持,则期待定义相应的 FP_FAST_FMA* 宏,但多数实现即使在不定义这些宏时也利用该 CPU 指令。
POSIX 指定 x * y 非法且 z 为 NaN 的情形是定义域错误。
由于其无限的中间精度,fma 是其他正确舍入数学运算,如 sqrt 或甚至除法(在 CPU 不支持的平台上,例如 Itanium)的常用构建块。
同所有浮点数表达式,表达式 (x*y) + z 可编译为融合乘加,除非 #pragma STDC FP_CONTRACT 为关闭。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.13.1 The fma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.10.1 The fma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.13.1 The fma functions (第 188-189 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.10.1 The fma functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.13.1 The fma functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.10.1 The fma functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.13.1 The fma functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.10.1 The fma functions (第 466 页)
参阅
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
|---|---|
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fma 的 C++ 文档 |
fmax
原址:https://zh.cppreference.com/w/c/numeric/math/fmax
作用:确定两个浮点数的较大者 (函数)
备注:
| |
1-3) 返回二个浮点数实参的较大者,把 NaNs 当做缺失数据(在 NaN 和数值间选择数值)。
4) 泛型宏:若任一参数拥有 long double 类型,则调用 fmaxl。否则,若任一实参拥有整数类型或 double 类型,则调用 fmax。否则调用 fmaxf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回二个浮点数的较大者。返回值准确且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若两个实参之一为 NaN,则返回另一实参的值
- 仅若两个实参均为 NaN,才返回 NaN
注意
不要求此函数对零的符号敏感,尽管某些实现额外强制若一个实参是 +0 而另一个是 -0,则返回 +0。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.2 The fmax functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.2 The fmax functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.2 The fmax functions (第 188 页)
7.25 Type-generic math <tgmath.h> (第 397 页)
F.10.9.2 The fmax functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.2 The fmax functions (第 257-258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.2 The fmax functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.2 The fmax functions (第 238-239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.2 The fmax functions (第 466 页)
参阅
| isgreater (C99) | 检查第一个浮点数实参是否大于第二个 (宏函数) |
|---|---|
| fmin (C99) fminf (C99) fminl (C99) | 确定两个浮点数的较小者 (函数) |
| fmax 的 C++ 文档 |
fmaxf
原址:https://zh.cppreference.com/w/c/numeric/math/fmax
作用:确定两个浮点数的较大者 (函数)
备注:
| |
1-3) 返回二个浮点数实参的较大者,把 NaNs 当做缺失数据(在 NaN 和数值间选择数值)。
4) 泛型宏:若任一参数拥有 long double 类型,则调用 fmaxl。否则,若任一实参拥有整数类型或 double 类型,则调用 fmax。否则调用 fmaxf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回二个浮点数的较大者。返回值准确且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若两个实参之一为 NaN,则返回另一实参的值
- 仅若两个实参均为 NaN,才返回 NaN
注意
不要求此函数对零的符号敏感,尽管某些实现额外强制若一个实参是 +0 而另一个是 -0,则返回 +0。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.2 The fmax functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.2 The fmax functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.2 The fmax functions (第 188 页)
7.25 Type-generic math <tgmath.h> (第 397 页)
F.10.9.2 The fmax functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.2 The fmax functions (第 257-258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.2 The fmax functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.2 The fmax functions (第 238-239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.2 The fmax functions (第 466 页)
参阅
| isgreater (C99) | 检查第一个浮点数实参是否大于第二个 (宏函数) |
|---|---|
| fmin (C99) fminf (C99) fminl (C99) | 确定两个浮点数的较小者 (函数) |
| fmax 的 C++ 文档 |
fmaxl
原址:https://zh.cppreference.com/w/c/numeric/math/fmax
作用:确定两个浮点数的较大者 (函数)
备注:
| |
1-3) 返回二个浮点数实参的较大者,把 NaNs 当做缺失数据(在 NaN 和数值间选择数值)。
4) 泛型宏:若任一参数拥有 long double 类型,则调用 fmaxl。否则,若任一实参拥有整数类型或 double 类型,则调用 fmax。否则调用 fmaxf。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回二个浮点数的较大者。返回值准确且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若两个实参之一为 NaN,则返回另一实参的值
- 仅若两个实参均为 NaN,才返回 NaN
注意
不要求此函数对零的符号敏感,尽管某些实现额外强制若一个实参是 +0 而另一个是 -0,则返回 +0。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.2 The fmax functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.2 The fmax functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.2 The fmax functions (第 188 页)
7.25 Type-generic math <tgmath.h> (第 397 页)
F.10.9.2 The fmax functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.2 The fmax functions (第 257-258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.2 The fmax functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.2 The fmax functions (第 238-239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.2 The fmax functions (第 466 页)
参阅
| isgreater (C99) | 检查第一个浮点数实参是否大于第二个 (宏函数) |
|---|---|
| fmin (C99) fminf (C99) fminl (C99) | 确定两个浮点数的较小者 (函数) |
| fmax 的 C++ 文档 |
fmin
原址:https://zh.cppreference.com/w/c/numeric/math/fmin
作用:确定两个浮点数的较小者 (函数)
备注:
| |
1-3) 返回二个浮点数参数的较小者,把 NaNs 当做缺失数据(在 NaN 和数值间选择数值)。
4) 泛型宏:若任一实参拥有 long double 类型,则调用 fmaxl。否则,若任一实参拥有整数类型或 double 类型,则调用 fmax。否则调用 fmaxf 。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回两个浮点数的较小者。返回值准确且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若两个参数之一为 NaN,则返回另一实参的值
- 仅若两个参数均为 NaN,才返回 NaN
注解
不要求此函数对零的符号敏感,尽管某些实现额外强制若一个实参是 +0 而另一个是 -0,则返回 -0。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.3 The fmin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.3 The fmin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.3 The fmin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.3 The fmin functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.3 The fmin functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.3 The fmin functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.3 The fmin functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.3 The fmin functions (第 466 页)
参阅
| isless (C99) | 检查第一个浮点数实参是否小于第二个 (宏函数) |
|---|---|
| fmax (C99) fmaxf (C99) fmaxl (C99) | 确定两个浮点数的较大者 (函数) |
| fmin 的 C++ 文档 |
fminf
原址:https://zh.cppreference.com/w/c/numeric/math/fmin
作用:确定两个浮点数的较小者 (函数)
备注:
| |
1-3) 返回二个浮点数参数的较小者,把 NaNs 当做缺失数据(在 NaN 和数值间选择数值)。
4) 泛型宏:若任一实参拥有 long double 类型,则调用 fmaxl。否则,若任一实参拥有整数类型或 double 类型,则调用 fmax。否则调用 fmaxf 。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回两个浮点数的较小者。返回值准确且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若两个参数之一为 NaN,则返回另一实参的值
- 仅若两个参数均为 NaN,才返回 NaN
注解
不要求此函数对零的符号敏感,尽管某些实现额外强制若一个实参是 +0 而另一个是 -0,则返回 -0。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.3 The fmin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.3 The fmin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.3 The fmin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.3 The fmin functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.3 The fmin functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.3 The fmin functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.3 The fmin functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.3 The fmin functions (第 466 页)
参阅
| isless (C99) | 检查第一个浮点数实参是否小于第二个 (宏函数) |
|---|---|
| fmax (C99) fmaxf (C99) fmaxl (C99) | 确定两个浮点数的较大者 (函数) |
| fmin 的 C++ 文档 |
fminl
原址:https://zh.cppreference.com/w/c/numeric/math/fmin
作用:确定两个浮点数的较小者 (函数)
备注:
| |
1-3) 返回二个浮点数参数的较小者,把 NaNs 当做缺失数据(在 NaN 和数值间选择数值)。
4) 泛型宏:若任一实参拥有 long double 类型,则调用 fmaxl。否则,若任一实参拥有整数类型或 double 类型,则调用 fmax。否则调用 fmaxf 。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回两个浮点数的较小者。返回值准确且不依赖任何舍入模式。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误条件。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若两个参数之一为 NaN,则返回另一实参的值
- 仅若两个参数均为 NaN,才返回 NaN
注解
不要求此函数对零的符号敏感,尽管某些实现额外强制若一个实参是 +0 而另一个是 -0,则返回 -0。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.12.3 The fmin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.3 The fmin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.12.3 The fmin functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.9.3 The fmin functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.12.3 The fmin functions (第 258 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.9.3 The fmin functions (第 530 页)
C99 标准(ISO/IEC 9899:1999):
7.12.12.3 The fmin functions (第 239 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.9.3 The fmin functions (第 466 页)
参阅
| isless (C99) | 检查第一个浮点数实参是否小于第二个 (宏函数) |
|---|---|
| fmax (C99) fmaxf (C99) fmaxl (C99) | 确定两个浮点数的较大者 (函数) |
| fmin 的 C++ 文档 |
fmod
原址:https://zh.cppreference.com/w/c/numeric/math/fmod
作用:计算浮点数除法运算的余数 (函数)
备注:
| |
1-3) 计算除法运算 x / y 的浮点数余数。
4) 泛型宏:若任何实参拥有 long double 类型则调用 fmodl。否则,若任何实参拥有整数类型或 double 类型则调用 fmod。否则调用 fmodf。
此函数计算的除法 x / y 的浮点数余数是 x - n * y 的准确值,其中 n 是截断小数部分的 x / y。
返回值与 x 拥有相同符号,且绝对值小于 y。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回定义于上的除法 x / y 的浮点数余数。
若出现定义域错误,则返回实现定义值(受支持的平台上为 NaN)。
若出现下溢所指定值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能发生定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559):
- 若
x为 ±0 且y非零,则返回 ±0。 - 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±∞ 且x有限,则返回x。 - 若任一实参为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
fmod,但不是 remainder,适于安静地包装浮点数类型到无符号整数类型:(0.0 <= (y = fmod( [rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0 )) ? y : 65536.0 + y) 在范围 [``-0.0``, ``65535.0``] 内,它对应 unsigned short,但 [remainder](http://zh.cppreference.com/w/c/numeric/math/remainder)([rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0) 在范围 [``-32767.0``, ``+32768.0``] 内,它在 signed short 的范围外。
fmod 的 double 版本表现为如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.1 The fmod functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.1 The fmod functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.1 The fmod functions (第 185 页)
7.25 Type-generic math <tgmath.h> (第 274-275 页)
F.10.7.1 The fmod functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.1 The fmod functions (第 254 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.1 The fmod functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.1 The fmod functions (第 235 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.1 The fmod functions (第 465 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.4 The fmod function
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fmod 的 C++ 文档 |
fmodf
原址:https://zh.cppreference.com/w/c/numeric/math/fmod
作用:计算浮点数除法运算的余数 (函数)
备注:
| |
1-3) 计算除法运算 x / y 的浮点数余数。
4) 泛型宏:若任何实参拥有 long double 类型则调用 fmodl。否则,若任何实参拥有整数类型或 double 类型则调用 fmod。否则调用 fmodf。
此函数计算的除法 x / y 的浮点数余数是 x - n * y 的准确值,其中 n 是截断小数部分的 x / y。
返回值与 x 拥有相同符号,且绝对值小于 y。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回定义于上的除法 x / y 的浮点数余数。
若出现定义域错误,则返回实现定义值(受支持的平台上为 NaN)。
若出现下溢所指定值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能发生定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559):
- 若
x为 ±0 且y非零,则返回 ±0。 - 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±∞ 且x有限,则返回x。 - 若任一实参为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
fmod,但不是 remainder,适于安静地包装浮点数类型到无符号整数类型:(0.0 <= (y = fmod( [rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0 )) ? y : 65536.0 + y) 在范围 [``-0.0``, ``65535.0``] 内,它对应 unsigned short,但 [remainder](http://zh.cppreference.com/w/c/numeric/math/remainder)([rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0) 在范围 [``-32767.0``, ``+32768.0``] 内,它在 signed short 的范围外。
fmod 的 double 版本表现为如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.1 The fmod functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.1 The fmod functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.1 The fmod functions (第 185 页)
7.25 Type-generic math <tgmath.h> (第 274-275 页)
F.10.7.1 The fmod functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.1 The fmod functions (第 254 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.1 The fmod functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.1 The fmod functions (第 235 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.1 The fmod functions (第 465 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.4 The fmod function
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fmod 的 C++ 文档 |
fmodl
原址:https://zh.cppreference.com/w/c/numeric/math/fmod
作用:计算浮点数除法运算的余数 (函数)
备注:
| |
1-3) 计算除法运算 x / y 的浮点数余数。
4) 泛型宏:若任何实参拥有 long double 类型则调用 fmodl。否则,若任何实参拥有整数类型或 double 类型则调用 fmod。否则调用 fmodf。
此函数计算的除法 x / y 的浮点数余数是 x - n * y 的准确值,其中 n 是截断小数部分的 x / y。
返回值与 x 拥有相同符号,且绝对值小于 y。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回定义于上的除法 x / y 的浮点数余数。
若出现定义域错误,则返回实现定义值(受支持的平台上为 NaN)。
若出现下溢所指定值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能发生定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559):
- 若
x为 ±0 且y非零,则返回 ±0。 - 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±∞ 且x有限,则返回x。 - 若任一实参为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
fmod,但不是 remainder,适于安静地包装浮点数类型到无符号整数类型:(0.0 <= (y = fmod( [rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0 )) ? y : 65536.0 + y) 在范围 [``-0.0``, ``65535.0``] 内,它对应 unsigned short,但 [remainder](http://zh.cppreference.com/w/c/numeric/math/remainder)([rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0) 在范围 [``-32767.0``, ``+32768.0``] 内,它在 signed short 的范围外。
fmod 的 double 版本表现为如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.1 The fmod functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.1 The fmod functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.1 The fmod functions (第 185 页)
7.25 Type-generic math <tgmath.h> (第 274-275 页)
F.10.7.1 The fmod functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.1 The fmod functions (第 254 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.1 The fmod functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.1 The fmod functions (第 235 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.1 The fmod functions (第 465 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.6.4 The fmod function
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| fmod 的 C++ 文档 |
frexp
原址:https://zh.cppreference.com/w/c/numeric/math/frexp
作用:将数拆分成有效数字和 2 的幂次 (函数)
备注:
| |
1-3) 分解给定的浮点数 x 为正规化小数和二的整数幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 frexpl。否则,若 arg 拥有整数类型或 double 类型,则调用 frexp。否则调用 frexpf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 指向要存储指数到的整数的指针 |
返回值
若 arg 为零,则返回零并存储零于 *exp。
否则(若 arg 非零),若不出现错误,则返回范围 (-1;-0.5], [0.5; 1) 中的值 x,并存储整数为 *[exp](http://zh.cppreference.com/w/c/numeric/math/exp),满足 x×2(*exp)
=arg。
若存储于 *exp 的值在 int 范围外,则行为未指定。
若 arg 不是浮点数,则行为未指定。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回不修改的参数,并存储0于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 若
arg为 ±∞,则返回它,并存储未指定值于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 若
arg为 NaN,则返回 NaN,并存储未指定值于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 不引发浮点数异常。
- 若 FLT_RADIX 为
2(或 2 的幂),则返回值准确,忽略当前舍入模式。
注解
二进制系统(其中 FLT_RADIX 为 2)上,frexp 可实现为
{
*exp = (value == 0) ? 0 : (int)(1 + logb(value));
return scalbn(value, -(*exp));
}
函数 frexp 与其对偶 ldexp 能一起用于操纵浮点数的表示,而无需直接的位操作。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.4 The frexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.4 The frexp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.4 The frexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.4 The frexp functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.4 The frexp functions (第 243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.4 The frexp functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.4 The frexp functions (第 224 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.4 The frexp functions (第 458 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.2 The frexp function
参阅
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| ilogb (C99) ilogbf (C99) ilogbl (C99) | 提取给定数的指数(结果为整数) (函数) |
| modf modff (C99) modfl (C99) | 把一个数拆分成整数和小数部分 (函数) |
| frexp 的 C++ 文档 |
frexpf
原址:https://zh.cppreference.com/w/c/numeric/math/frexp
作用:将数拆分成有效数字和 2 的幂次 (函数)
备注:
| |
1-3) 分解给定的浮点数 x 为正规化小数和二的整数幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 frexpl。否则,若 arg 拥有整数类型或 double 类型,则调用 frexp。否则调用 frexpf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 指向要存储指数到的整数的指针 |
返回值
若 arg 为零,则返回零并存储零于 *exp。
否则(若 arg 非零),若不出现错误,则返回范围 (-1;-0.5], [0.5; 1) 中的值 x,并存储整数为 *[exp](http://zh.cppreference.com/w/c/numeric/math/exp),满足 x×2(*exp)
=arg。
若存储于 *exp 的值在 int 范围外,则行为未指定。
若 arg 不是浮点数,则行为未指定。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回不修改的参数,并存储0于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 若
arg为 ±∞,则返回它,并存储未指定值于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 若
arg为 NaN,则返回 NaN,并存储未指定值于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 不引发浮点数异常。
- 若 FLT_RADIX 为
2(或 2 的幂),则返回值准确,忽略当前舍入模式。
注解
二进制系统(其中 FLT_RADIX 为 2)上,frexp 可实现为
{
*exp = (value == 0) ? 0 : (int)(1 + logb(value));
return scalbn(value, -(*exp));
}
函数 frexp 与其对偶 ldexp 能一起用于操纵浮点数的表示,而无需直接的位操作。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.4 The frexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.4 The frexp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.4 The frexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.4 The frexp functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.4 The frexp functions (第 243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.4 The frexp functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.4 The frexp functions (第 224 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.4 The frexp functions (第 458 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.2 The frexp function
参阅
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| ilogb (C99) ilogbf (C99) ilogbl (C99) | 提取给定数的指数(结果为整数) (函数) |
| modf modff (C99) modfl (C99) | 把一个数拆分成整数和小数部分 (函数) |
| frexp 的 C++ 文档 |
frexpl
原址:https://zh.cppreference.com/w/c/numeric/math/frexp
作用:将数拆分成有效数字和 2 的幂次 (函数)
备注:
| |
1-3) 分解给定的浮点数 x 为正规化小数和二的整数幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 frexpl。否则,若 arg 拥有整数类型或 double 类型,则调用 frexp。否则调用 frexpf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 指向要存储指数到的整数的指针 |
返回值
若 arg 为零,则返回零并存储零于 *exp。
否则(若 arg 非零),若不出现错误,则返回范围 (-1;-0.5], [0.5; 1) 中的值 x,并存储整数为 *[exp](http://zh.cppreference.com/w/c/numeric/math/exp),满足 x×2(*exp)
=arg。
若存储于 *exp 的值在 int 范围外,则行为未指定。
若 arg 不是浮点数,则行为未指定。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回不修改的参数,并存储0于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 若
arg为 ±∞,则返回它,并存储未指定值于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 若
arg为 NaN,则返回 NaN,并存储未指定值于*[exp](http://zh.cppreference.com/w/c/numeric/math/exp)。 - 不引发浮点数异常。
- 若 FLT_RADIX 为
2(或 2 的幂),则返回值准确,忽略当前舍入模式。
注解
二进制系统(其中 FLT_RADIX 为 2)上,frexp 可实现为
{
*exp = (value == 0) ? 0 : (int)(1 + logb(value));
return scalbn(value, -(*exp));
}
函数 frexp 与其对偶 ldexp 能一起用于操纵浮点数的表示,而无需直接的位操作。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.4 The frexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.4 The frexp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.4 The frexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.4 The frexp functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.4 The frexp functions (第 243 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.4 The frexp functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.4 The frexp functions (第 224 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.4 The frexp functions (第 458 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.2 The frexp function
参阅
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| ilogb (C99) ilogbf (C99) ilogbl (C99) | 提取给定数的指数(结果为整数) (函数) |
| modf modff (C99) modfl (C99) | 把一个数拆分成整数和小数部分 (函数) |
| frexp 的 C++ 文档 |
hypot
原址:https://zh.cppreference.com/w/c/numeric/math/hypot
作用:计算两个给定数平方和的平方根(\scriptsize{\sqrt{x^2+y^2} }\scriptsize{\sqrt{x^2+y^2} }√x2+y2) (函数)
备注:
| |
1-3) 计算 x 与 y 平方和的平方根,而不会在计算的中间阶段有过度的上溢或下溢。
4) 泛型宏:若任何实参拥有 long double 类型,则调用函数的 long double 版本。否则,若任何实参拥有整数类型或 double 类型,则调用函数的 double 版本。否则,调用函数的 float 版本。
此函数计算的值是直角边长度为 x 和 y 的直角三角形的斜边长,或点 (x, y) 距原点 (0, 0) 的距离,或复数 x+*i*y 的绝对值。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若不出现错误,则返回直角三角形的斜边,√x2+y2x2+y2。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
hypot(x, y)、hypot(y, x)及hypot(x, -y)等价- 若实参之一为 ±0,则
hypot等价于以非零实参调用[fabs](http://zh.cppreference.com/w/c/numeric/math/fabs) - 若实参之一为 ±∞,则
hypot返回 +∞,即使另一参数为 NaN - 否则,若任何实参为 NaN,则返回 NaN
注解
实现通常保证小于 1 ulp(最后位置单位)的精度:GNU、BSD。
hypot(x, y) 等价于 [cabs](http://zh.cppreference.com/w/c/numeric/complex/cabs)(x + I*y)。
POSIX 指定仅若两个实参均为非正规且正确结果亦为非正规才可以出现下溢(这禁止朴素实现)。
hypot(INFINITY, NAN) 返回 +∞,但 [sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(INFINITY * INFINITY + NAN * NAN) 返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.3 The hypot functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.3 The hypot functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.3 The hypot functions (第 181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.3 The hypot functions (第 382 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.3 The hypot functions (第 248 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.3 The hypot functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.3 The hypot functions (第 229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.3 The hypot functions (第 461 页)
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| cabs (C99) cabsf (C99) cabsl (C99) | 计算复数的模(绝对值) (函数) |
| hypot 的 C++ 文档 |
hypotf
原址:https://zh.cppreference.com/w/c/numeric/math/hypot
作用:计算两个给定数平方和的平方根(\scriptsize{\sqrt{x^2+y^2} }\scriptsize{\sqrt{x^2+y^2} }√x2+y2) (函数)
备注:
| |
1-3) 计算 x 与 y 平方和的平方根,而不会在计算的中间阶段有过度的上溢或下溢。
4) 泛型宏:若任何实参拥有 long double 类型,则调用函数的 long double 版本。否则,若任何实参拥有整数类型或 double 类型,则调用函数的 double 版本。否则,调用函数的 float 版本。
此函数计算的值是直角边长度为 x 和 y 的直角三角形的斜边长,或点 (x, y) 距原点 (0, 0) 的距离,或复数 x+*i*y 的绝对值。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若不出现错误,则返回直角三角形的斜边,√x2+y2x2+y2。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
hypot(x, y)、hypot(y, x)及hypot(x, -y)等价- 若实参之一为 ±0,则
hypot等价于以非零实参调用[fabs](http://zh.cppreference.com/w/c/numeric/math/fabs) - 若实参之一为 ±∞,则
hypot返回 +∞,即使另一参数为 NaN - 否则,若任何实参为 NaN,则返回 NaN
注解
实现通常保证小于 1 ulp(最后位置单位)的精度:GNU、BSD。
hypot(x, y) 等价于 [cabs](http://zh.cppreference.com/w/c/numeric/complex/cabs)(x + I*y)。
POSIX 指定仅若两个实参均为非正规且正确结果亦为非正规才可以出现下溢(这禁止朴素实现)。
hypot(INFINITY, NAN) 返回 +∞,但 [sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(INFINITY * INFINITY + NAN * NAN) 返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.3 The hypot functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.3 The hypot functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.3 The hypot functions (第 181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.3 The hypot functions (第 382 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.3 The hypot functions (第 248 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.3 The hypot functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.3 The hypot functions (第 229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.3 The hypot functions (第 461 页)
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| cabs (C99) cabsf (C99) cabsl (C99) | 计算复数的模(绝对值) (函数) |
| hypot 的 C++ 文档 |
hypotl
原址:https://zh.cppreference.com/w/c/numeric/math/hypot
作用:计算两个给定数平方和的平方根(\scriptsize{\sqrt{x^2+y^2} }\scriptsize{\sqrt{x^2+y^2} }√x2+y2) (函数)
备注:
| |
1-3) 计算 x 与 y 平方和的平方根,而不会在计算的中间阶段有过度的上溢或下溢。
4) 泛型宏:若任何实参拥有 long double 类型,则调用函数的 long double 版本。否则,若任何实参拥有整数类型或 double 类型,则调用函数的 double 版本。否则,调用函数的 float 版本。
此函数计算的值是直角边长度为 x 和 y 的直角三角形的斜边长,或点 (x, y) 距原点 (0, 0) 的距离,或复数 x+*i*y 的绝对值。
参数
| x | - | 浮点数 |
|---|---|---|
| y | - | 浮点数 |
返回值
若不出现错误,则返回直角三角形的斜边,√x2+y2x2+y2。
若出现上溢所致的值域错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
hypot(x, y)、hypot(y, x)及hypot(x, -y)等价- 若实参之一为 ±0,则
hypot等价于以非零实参调用[fabs](http://zh.cppreference.com/w/c/numeric/math/fabs) - 若实参之一为 ±∞,则
hypot返回 +∞,即使另一参数为 NaN - 否则,若任何实参为 NaN,则返回 NaN
注解
实现通常保证小于 1 ulp(最后位置单位)的精度:GNU、BSD。
hypot(x, y) 等价于 [cabs](http://zh.cppreference.com/w/c/numeric/complex/cabs)(x + I*y)。
POSIX 指定仅若两个实参均为非正规且正确结果亦为非正规才可以出现下溢(这禁止朴素实现)。
hypot(INFINITY, NAN) 返回 +∞,但 [sqrt](http://zh.cppreference.com/w/c/numeric/math/sqrt)(INFINITY * INFINITY + NAN * NAN) 返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.3 The hypot functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.3 The hypot functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.3 The hypot functions (第 181 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.4.3 The hypot functions (第 382 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.3 The hypot functions (第 248 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.3 The hypot functions (第 524 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.3 The hypot functions (第 229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.3 The hypot functions (第 461 页)
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| cabs (C99) cabsf (C99) cabsl (C99) | 计算复数的模(绝对值) (函数) |
| hypot 的 C++ 文档 |
ilogb
原址:https://zh.cppreference.com/w/c/numeric/math/ilogb
作用:提取给定数的指数(结果为整数) (函数)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为有符号整数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ilogbl。否则,若 arg 拥有整数类型或 double 类型,则调用 ilogb。否则调用 ilogbf。
5) 展开成整数常量表达式,值为 INT_MIN 或 -[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
6) 展开成整数常量表达式,值为 INT_MIN 或 +[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
正式而言,无偏指数是非零 arg 的 logr|arg| 的整数部分,作为有符号整数,其中 r 是 FLT_RADIX。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为 int 值的 arg 的无偏指数。
若 arg 为零,则返回 FP_ILOGB0。
若 arg 为无穷大,则返回 INT_MAX。
若 arg 为 NaN,则返回 FP_ILOGBNAN。
若正确结果大于 INT_MAX 或小于 INT_MIN,则返回值未指定,且可能出现定义域或值域错误。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零、无穷大或 NaN ,则可能出现定义域错误或值域错误。
若正确结果大于 INT_MAX 或小于 INT_MIN ,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若正确结果大于 INT_MAX 或小于 INT_MIN,则引发 FE_INVALID。
- 若
arg为 ±0、 ±∞ 或 NaN,则引发 FE_INVALID。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)并且忽略当前舍入模式。
注解
若 arg 不是零、无穷大或 NaN,则返回的值准确等价于 (int)[logb](http://zh.cppreference.com/w/c/numeric/math/logb)(arg)。
POSIX 要求若 arg 为零、无穷大、NaN 或若正确结果在 int 的范围外则出现定义域错误。
POSIX 亦要求在 XSI 一致的系统上,正确结果大于 INT_MAX 时返回值为 INT_MAX,而正确结果小于 INT_MIN 时返回值为 INT_MIN。
在所有已知平台上正确结果都能表示成 int。对于要出现溢出的情况,INT_MAX 必须小于 [LDBL_MAX_EXP](http://zh.cppreference.com/w/c/types/limits) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits)) 或 INT_MIN 必须大于 [LDBL_MIN_EXP](http://zh.cppreference.com/w/c/types/limits) - [LDBL_MANT_DIG](http://zh.cppreference.com/w/c/types/limits)) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits))。
ilogb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 ilogb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/8 Mathematics <math.h> (第 232 页)
7.12.6.5 The ilogb functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.5 The ilogb functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12/8 Mathematics <math.h> (第 213 页)
7.12.6.5 The ilogb functions (第 224-225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.5 The ilogb functions (第 458 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ilogb 的 C++ 文档 |
ilogbf
原址:https://zh.cppreference.com/w/c/numeric/math/ilogb
作用:提取给定数的指数(结果为整数) (函数)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为有符号整数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ilogbl。否则,若 arg 拥有整数类型或 double 类型,则调用 ilogb。否则调用 ilogbf。
5) 展开成整数常量表达式,值为 INT_MIN 或 -[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
6) 展开成整数常量表达式,值为 INT_MIN 或 +[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
正式而言,无偏指数是非零 arg 的 logr|arg| 的整数部分,作为有符号整数,其中 r 是 FLT_RADIX。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为 int 值的 arg 的无偏指数。
若 arg 为零,则返回 FP_ILOGB0。
若 arg 为无穷大,则返回 INT_MAX。
若 arg 为 NaN,则返回 FP_ILOGBNAN。
若正确结果大于 INT_MAX 或小于 INT_MIN,则返回值未指定,且可能出现定义域或值域错误。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零、无穷大或 NaN ,则可能出现定义域错误或值域错误。
若正确结果大于 INT_MAX 或小于 INT_MIN ,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若正确结果大于 INT_MAX 或小于 INT_MIN,则引发 FE_INVALID。
- 若
arg为 ±0、 ±∞ 或 NaN,则引发 FE_INVALID。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)并且忽略当前舍入模式。
注解
若 arg 不是零、无穷大或 NaN,则返回的值准确等价于 (int)[logb](http://zh.cppreference.com/w/c/numeric/math/logb)(arg)。
POSIX 要求若 arg 为零、无穷大、NaN 或若正确结果在 int 的范围外则出现定义域错误。
POSIX 亦要求在 XSI 一致的系统上,正确结果大于 INT_MAX 时返回值为 INT_MAX,而正确结果小于 INT_MIN 时返回值为 INT_MIN。
在所有已知平台上正确结果都能表示成 int。对于要出现溢出的情况,INT_MAX 必须小于 [LDBL_MAX_EXP](http://zh.cppreference.com/w/c/types/limits) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits)) 或 INT_MIN 必须大于 [LDBL_MIN_EXP](http://zh.cppreference.com/w/c/types/limits) - [LDBL_MANT_DIG](http://zh.cppreference.com/w/c/types/limits)) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits))。
ilogb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 ilogb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/8 Mathematics <math.h> (第 232 页)
7.12.6.5 The ilogb functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.5 The ilogb functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12/8 Mathematics <math.h> (第 213 页)
7.12.6.5 The ilogb functions (第 224-225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.5 The ilogb functions (第 458 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ilogb 的 C++ 文档 |
ilogbl
原址:https://zh.cppreference.com/w/c/numeric/math/ilogb
作用:提取给定数的指数(结果为整数) (函数)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为有符号整数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ilogbl。否则,若 arg 拥有整数类型或 double 类型,则调用 ilogb。否则调用 ilogbf。
5) 展开成整数常量表达式,值为 INT_MIN 或 -[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
6) 展开成整数常量表达式,值为 INT_MIN 或 +[INT_MAX](http://zh.cppreference.com/w/c/types/limits)。
正式而言,无偏指数是非零 arg 的 logr|arg| 的整数部分,作为有符号整数,其中 r 是 FLT_RADIX。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为 int 值的 arg 的无偏指数。
若 arg 为零,则返回 FP_ILOGB0。
若 arg 为无穷大,则返回 INT_MAX。
若 arg 为 NaN,则返回 FP_ILOGBNAN。
若正确结果大于 INT_MAX 或小于 INT_MIN,则返回值未指定,且可能出现定义域或值域错误。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零、无穷大或 NaN ,则可能出现定义域错误或值域错误。
若正确结果大于 INT_MAX 或小于 INT_MIN ,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若正确结果大于 INT_MAX 或小于 INT_MIN,则引发 FE_INVALID。
- 若
arg为 ±0、 ±∞ 或 NaN,则引发 FE_INVALID。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)并且忽略当前舍入模式。
注解
若 arg 不是零、无穷大或 NaN,则返回的值准确等价于 (int)[logb](http://zh.cppreference.com/w/c/numeric/math/logb)(arg)。
POSIX 要求若 arg 为零、无穷大、NaN 或若正确结果在 int 的范围外则出现定义域错误。
POSIX 亦要求在 XSI 一致的系统上,正确结果大于 INT_MAX 时返回值为 INT_MAX,而正确结果小于 INT_MIN 时返回值为 INT_MIN。
在所有已知平台上正确结果都能表示成 int。对于要出现溢出的情况,INT_MAX 必须小于 [LDBL_MAX_EXP](http://zh.cppreference.com/w/c/types/limits) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits)) 或 INT_MIN 必须大于 [LDBL_MIN_EXP](http://zh.cppreference.com/w/c/types/limits) - [LDBL_MANT_DIG](http://zh.cppreference.com/w/c/types/limits)) * log2([FLT_RADIX](http://zh.cppreference.com/w/c/types/limits))。
ilogb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 ilogb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12/8 Mathematics <math.h> (第 TBD 页)
7.12.6.5 The ilogb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.5 The ilogb functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12/8 Mathematics <math.h> (第 232 页)
7.12.6.5 The ilogb functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.5 The ilogb functions (第 521 页)
C99 标准(ISO/IEC 9899:1999):
7.12/8 Mathematics <math.h> (第 213 页)
7.12.6.5 The ilogb functions (第 224-225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.5 The ilogb functions (第 458 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| logb (C99) logbf (C99) logbl (C99) | 提取给定数的指数(结果为浮点数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ilogb 的 C++ 文档 |
ldexp
原址:https://zh.cppreference.com/w/c/numeric/math/ldexp
作用:将数乘以 2 的幂 (函数)
备注:
| |
1-3) 将浮点数 arg 乘以 2 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ldexpl。否则,若 arg 拥有整数类型或 double 类型,则调用 ldexp。否则调用 ldexpf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 2 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×2exp
*)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),ldexp 等价于 scalbn。
函数 ldexp(“加载指数”)与其对偶 frexp 能一同用于操纵浮点数的表示,而无需直接的位操作。
多数实现上,ldexp 效率低于用通常算术运算符乘或除以二的幂。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.6 The ldexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.6 The ldexp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.6 The ldexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.6 The ldexp functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.6 The ldexp functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.6 The ldexp functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.6 The ldexp functions (第 225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.6 The ldexp functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.3 The ldexp function
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ldexp 的 C++ 文档 |
ldexpf
原址:https://zh.cppreference.com/w/c/numeric/math/ldexp
作用:将数乘以 2 的幂 (函数)
备注:
| |
1-3) 将浮点数 arg 乘以 2 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ldexpl。否则,若 arg 拥有整数类型或 double 类型,则调用 ldexp。否则调用 ldexpf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 2 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×2exp
*)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),ldexp 等价于 scalbn。
函数 ldexp(“加载指数”)与其对偶 frexp 能一同用于操纵浮点数的表示,而无需直接的位操作。
多数实现上,ldexp 效率低于用通常算术运算符乘或除以二的幂。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.6 The ldexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.6 The ldexp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.6 The ldexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.6 The ldexp functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.6 The ldexp functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.6 The ldexp functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.6 The ldexp functions (第 225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.6 The ldexp functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.3 The ldexp function
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ldexp 的 C++ 文档 |
ldexpl
原址:https://zh.cppreference.com/w/c/numeric/math/ldexp
作用:将数乘以 2 的幂 (函数)
备注:
| |
1-3) 将浮点数 arg 乘以 2 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 ldexpl。否则,若 arg 拥有整数类型或 double 类型,则调用 ldexp。否则调用 ldexpf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 2 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×2exp
*)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),ldexp 等价于 scalbn。
函数 ldexp(“加载指数”)与其对偶 frexp 能一同用于操纵浮点数的表示,而无需直接的位操作。
多数实现上,ldexp 效率低于用通常算术运算符乘或除以二的幂。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.6 The ldexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.6 The ldexp functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.6 The ldexp functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.6 The ldexp functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.6 The ldexp functions (第 244 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.6 The ldexp functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.6 The ldexp functions (第 225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.6 The ldexp functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.3 The ldexp function
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| ldexp 的 C++ 文档 |
lgamma
原址:https://zh.cppreference.com/w/c/numeric/math/lgamma
作用:计算伽马函数的自然对数(底为 e) (函数)
备注:
| |
1-3) 计算 arg 的伽马函数绝对值的自然对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 lgammal。否则,若 arg 拥有整数类型或 double 类型,则调用 lgamma。否则调用lgammaf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的伽马函数的自然对数,即 loge|∫∞0targ−1e−tdt|loge|∫0∞targ−1e−tdt|。
若出现极点错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零或为小于零的整数,则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 1,则返回 +0。
- 若实参为 2,则返回 +0。
- 若实参为 ±0,则返回 +∞ 并引发 FE_DIVBYZERO。
- 若实参为负整数,则返回 +∞ 并引发 FE_DIVBYZERO。
- 若实参为 ±∞,则返回 +∞。
- 若实参为 NaN,则返回 NaN。
注解
若 arg 为自然数,则 lgamma(arg) 是 arg-1 阶乘的自然对数。
lgamma 的 POSIX 版本不是线程安全的:每次执行函数都会存储 arg 的伽马函数的符号于静态外部变量 signgam。一些实现提供 lgamma_r,它接收指向 singgam 的用户提供存储的指针为第二参数,而且是线程安全的。
多数实现中有名为 gamma 的非标准函数,但其定义不一致。例如,gamma 的 glibc 和 4.2BSD 版本执行 lgamma,但 gamma 的 4.4BSD 版本执行 tgamma。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.3 The lgamma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.5.3 The lgamma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.3 The lgamma functions (第 182 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.5.3 The lgamma functions (第 383 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.3 The lgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.3 The lgamma functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.3 The lgamma functions (第 231 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.3 The lgamma functions (第 462 页)
参阅
| tgamma (C99) tgammaf (C99) tgammal (C99) | 计算伽马函数 (函数) |
|---|---|
| lgamma 的 C++ 文档 |
外部链接
Weisstein, Eric W. “对数伽马函数”来自 MathWorld–A Wolfram Web Resource。
lgammaf
原址:https://zh.cppreference.com/w/c/numeric/math/lgamma
作用:计算伽马函数的自然对数(底为 e) (函数)
备注:
| |
1-3) 计算 arg 的伽马函数绝对值的自然对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 lgammal。否则,若 arg 拥有整数类型或 double 类型,则调用 lgamma。否则调用lgammaf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的伽马函数的自然对数,即 loge|∫∞0targ−1e−tdt|loge|∫0∞targ−1e−tdt|。
若出现极点错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零或为小于零的整数,则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 1,则返回 +0。
- 若实参为 2,则返回 +0。
- 若实参为 ±0,则返回 +∞ 并引发 FE_DIVBYZERO。
- 若实参为负整数,则返回 +∞ 并引发 FE_DIVBYZERO。
- 若实参为 ±∞,则返回 +∞。
- 若实参为 NaN,则返回 NaN。
注解
若 arg 为自然数,则 lgamma(arg) 是 arg-1 阶乘的自然对数。
lgamma 的 POSIX 版本不是线程安全的:每次执行函数都会存储 arg 的伽马函数的符号于静态外部变量 signgam。一些实现提供 lgamma_r,它接收指向 singgam 的用户提供存储的指针为第二参数,而且是线程安全的。
多数实现中有名为 gamma 的非标准函数,但其定义不一致。例如,gamma 的 glibc 和 4.2BSD 版本执行 lgamma,但 gamma 的 4.4BSD 版本执行 tgamma。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.3 The lgamma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.5.3 The lgamma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.3 The lgamma functions (第 182 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.5.3 The lgamma functions (第 383 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.3 The lgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.3 The lgamma functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.3 The lgamma functions (第 231 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.3 The lgamma functions (第 462 页)
参阅
| tgamma (C99) tgammaf (C99) tgammal (C99) | 计算伽马函数 (函数) |
|---|---|
| lgamma 的 C++ 文档 |
外部链接
Weisstein, Eric W. “对数伽马函数”来自 MathWorld–A Wolfram Web Resource。
lgammal
原址:https://zh.cppreference.com/w/c/numeric/math/lgamma
作用:计算伽马函数的自然对数(底为 e) (函数)
备注:
| |
1-3) 计算 arg 的伽马函数绝对值的自然对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 lgammal。否则,若 arg 拥有整数类型或 double 类型,则调用 lgamma。否则调用lgammaf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的伽马函数的自然对数,即 loge|∫∞0targ−1e−tdt|loge|∫0∞targ−1e−tdt|。
若出现极点错误,则返回 +HUGE_VAL、+HUGE_VALF 或 +HUGE_VALL。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零或为小于零的整数,则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 1,则返回 +0。
- 若实参为 2,则返回 +0。
- 若实参为 ±0,则返回 +∞ 并引发 FE_DIVBYZERO。
- 若实参为负整数,则返回 +∞ 并引发 FE_DIVBYZERO。
- 若实参为 ±∞,则返回 +∞。
- 若实参为 NaN,则返回 NaN。
注解
若 arg 为自然数,则 lgamma(arg) 是 arg-1 阶乘的自然对数。
lgamma 的 POSIX 版本不是线程安全的:每次执行函数都会存储 arg 的伽马函数的符号于静态外部变量 signgam。一些实现提供 lgamma_r,它接收指向 singgam 的用户提供存储的指针为第二参数,而且是线程安全的。
多数实现中有名为 gamma 的非标准函数,但其定义不一致。例如,gamma 的 glibc 和 4.2BSD 版本执行 lgamma,但 gamma 的 4.4BSD 版本执行 tgamma。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.3 The lgamma functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.5.3 The lgamma functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.3 The lgamma functions (第 182 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.5.3 The lgamma functions (第 383 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.3 The lgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.3 The lgamma functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.3 The lgamma functions (第 231 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.3 The lgamma functions (第 462 页)
参阅
| tgamma (C99) tgammaf (C99) tgammal (C99) | 计算伽马函数 (函数) |
|---|---|
| lgamma 的 C++ 文档 |
外部链接
Weisstein, Eric W. “对数伽马函数”来自 MathWorld–A Wolfram Web Resource。
llrint
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
llrintf
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
llrintl
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
llround
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
llroundf
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
llroundl
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
log
原址:https://zh.cppreference.com/w/c/numeric/math/log
作用:计算自然对数(底为 e)({\small \ln{x} }{\small \ln{x} }ln(x)) (函数)
备注:
| |
1-3) 计算 arg 的自然(底 e)对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 logl。否则,若 arg 拥有整数类型或 double 类型,则调用 log。否则,调用 logf。若 arg 为复数或序数,则宏调用对应的复数函数([clogf](http://zh.cppreference.com/w/c/numeric/complex/clog)、[clog](http://zh.cppreference.com/w/c/numeric/complex/clog)、[clogl](http://zh.cppreference.com/w/c/numeric/complex/clog))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的自然(底 e)对数(ln(arg) 或 loge(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.7 The log functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.7 The log functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.7 The log functions (第 178-179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.7 The log functions (第 380 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.7 The log functions (第 244-245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.7 The log functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.7 The log functions (第 225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.7 The log functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.4 The log function
参阅
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
|---|---|
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
| clog (C99) clogf (C99) clogl (C99) | 计算复数的自然对数 (函数) |
| log 的 C++ 文档 |
log10
原址:https://zh.cppreference.com/w/c/numeric/math/log10
作用:计算常用对数 (底为 10)({\small \log_{10}{x} }{\small \log_{10}{x} }log10(x)) (函数)
备注:
| |
1-3) 计算 arg 的常用(以 10 为底)对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log10l。否则,若 arg 拥有整数类型或 double 类型,则调用 log10。否则调用 log10f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的常用(底 10)对数(log10(arg) 或 lg(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.8 The log10 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.8 The log10 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.8 The log10 functions (第 179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.8 The log10 functions (第 380 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.8 The log10 functions (第 245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.8 The log10 functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.8 The log10 functions (第 225-226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.8 The log10 functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.5 The log10 function
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| log10 的 C++ 文档 |
log10f
原址:https://zh.cppreference.com/w/c/numeric/math/log10
作用:计算常用对数 (底为 10)({\small \log_{10}{x} }{\small \log_{10}{x} }log10(x)) (函数)
备注:
| |
1-3) 计算 arg 的常用(以 10 为底)对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log10l。否则,若 arg 拥有整数类型或 double 类型,则调用 log10。否则调用 log10f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的常用(底 10)对数(log10(arg) 或 lg(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.8 The log10 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.8 The log10 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.8 The log10 functions (第 179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.8 The log10 functions (第 380 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.8 The log10 functions (第 245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.8 The log10 functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.8 The log10 functions (第 225-226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.8 The log10 functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.5 The log10 function
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| log10 的 C++ 文档 |
log10l
原址:https://zh.cppreference.com/w/c/numeric/math/log10
作用:计算常用对数 (底为 10)({\small \log_{10}{x} }{\small \log_{10}{x} }log10(x)) (函数)
备注:
| |
1-3) 计算 arg 的常用(以 10 为底)对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log10l。否则,若 arg 拥有整数类型或 double 类型,则调用 log10。否则调用 log10f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的常用(底 10)对数(log10(arg) 或 lg(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.8 The log10 functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.8 The log10 functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.8 The log10 functions (第 179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.8 The log10 functions (第 380 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.8 The log10 functions (第 245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.8 The log10 functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.8 The log10 functions (第 225-226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.8 The log10 functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.5 The log10 function
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| log10 的 C++ 文档 |
log1p
原址:https://zh.cppreference.com/w/c/numeric/math/log1p
作用:计算给定数加 1 的自然对数(底为 e)({\small \ln{(1+x)} }{\small \ln{(1+x)} }ln(1+x)) (函数)
备注:
| |
1-3) 计算 1 + arg 的自然(以 e 为底)对数。若 arg 接近零,则此函数比表达式 [log](http://zh.cppreference.com/w/c/numeric/math/log)(1 +arg) 更精确。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log1pl。否则,若 arg 拥有整数类型或 double 类型,则调用 log1p。否则调用 log1pf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误则返回 ln(1 + arg)。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于 -1 则出现定义域错误。
若 arg 为 -1 则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回不修改的参数。
- 若实参为 -1,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若实参小于 -1,则返回 NaN 并引发 FE_INVALID。
- 若实参为 +∞,则返回 +∞。
- 若实参为 NaN,则返回 NaN。
注意
函数 expm1 和 log1p 对于金融计算有用:例如在计算小的日利率时:(1+x)n
-1 能表示为 [expm1](http://zh.cppreference.com/w/c/numeric/math/expm1)(n * log1p(x))。这些函数亦简化书写精确的反双曲函数。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.9 The log1p functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.9 The log1p functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.9 The log1p functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.9 The log1p functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.9 The log1p functions (第 245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.9 The log1p functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.9 The log1p functions (第 226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.9 The log1p functions (第 459 页)
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log1p 的 C++ 文档 |
log1pf
原址:https://zh.cppreference.com/w/c/numeric/math/log1p
作用:计算给定数加 1 的自然对数(底为 e)({\small \ln{(1+x)} }{\small \ln{(1+x)} }ln(1+x)) (函数)
备注:
| |
1-3) 计算 1 + arg 的自然(以 e 为底)对数。若 arg 接近零,则此函数比表达式 [log](http://zh.cppreference.com/w/c/numeric/math/log)(1 +arg) 更精确。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log1pl。否则,若 arg 拥有整数类型或 double 类型,则调用 log1p。否则调用 log1pf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误则返回 ln(1 + arg)。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于 -1 则出现定义域错误。
若 arg 为 -1 则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回不修改的参数。
- 若实参为 -1,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若实参小于 -1,则返回 NaN 并引发 FE_INVALID。
- 若实参为 +∞,则返回 +∞。
- 若实参为 NaN,则返回 NaN。
注意
函数 expm1 和 log1p 对于金融计算有用:例如在计算小的日利率时:(1+x)n
-1 能表示为 [expm1](http://zh.cppreference.com/w/c/numeric/math/expm1)(n * log1p(x))。这些函数亦简化书写精确的反双曲函数。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.9 The log1p functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.9 The log1p functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.9 The log1p functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.9 The log1p functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.9 The log1p functions (第 245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.9 The log1p functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.9 The log1p functions (第 226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.9 The log1p functions (第 459 页)
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log1p 的 C++ 文档 |
log1pl
原址:https://zh.cppreference.com/w/c/numeric/math/log1p
作用:计算给定数加 1 的自然对数(底为 e)({\small \ln{(1+x)} }{\small \ln{(1+x)} }ln(1+x)) (函数)
备注:
| |
1-3) 计算 1 + arg 的自然(以 e 为底)对数。若 arg 接近零,则此函数比表达式 [log](http://zh.cppreference.com/w/c/numeric/math/log)(1 +arg) 更精确。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log1pl。否则,若 arg 拥有整数类型或 double 类型,则调用 log1p。否则调用 log1pf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误则返回 ln(1 + arg)。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于 -1 则出现定义域错误。
若 arg 为 -1 则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0,则返回不修改的参数。
- 若实参为 -1,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若实参小于 -1,则返回 NaN 并引发 FE_INVALID。
- 若实参为 +∞,则返回 +∞。
- 若实参为 NaN,则返回 NaN。
注意
函数 expm1 和 log1p 对于金融计算有用:例如在计算小的日利率时:(1+x)n
-1 能表示为 [expm1](http://zh.cppreference.com/w/c/numeric/math/expm1)(n * log1p(x))。这些函数亦简化书写精确的反双曲函数。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.9 The log1p functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.9 The log1p functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.9 The log1p functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.9 The log1p functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.9 The log1p functions (第 245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.9 The log1p functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.9 The log1p functions (第 226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.9 The log1p functions (第 459 页)
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| expm1 (C99) expm1f (C99) expm1l (C99) | 计算 e 的给定次幂减一(ex−1ex−1) (函数) |
| log1p 的 C++ 文档 |
log2
原址:https://zh.cppreference.com/w/c/numeric/math/log2
作用:计算底为 2 的对数({\small \log_{2}{x} }{\small \log_{2}{x} }log2(x)) (函数)
备注:
| |
1-3) 计算 arg 的底 2 对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log2l。否则,若 arg 拥有整数类型或 double 类型,则调用 log2。否则调用 log2f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的底 2 对数(log2(arg) 或 lb(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
注意
对于整数 arg,二进制对数能转译成输入中最高位 1 的零底下标。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12.6.10 The log2 functions (第 179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.10 The log2 functions (第 381 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.10 The log2 functions (第 246 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.10 The log2 functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.10 The log2 functions (第 226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.10 The log2 functions (第 459 页)
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
| log2 的 C++ 文档 |
log2f
原址:https://zh.cppreference.com/w/c/numeric/math/log2
作用:计算底为 2 的对数({\small \log_{2}{x} }{\small \log_{2}{x} }log2(x)) (函数)
备注:
| |
1-3) 计算 arg 的底 2 对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log2l。否则,若 arg 拥有整数类型或 double 类型,则调用 log2。否则调用 log2f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的底 2 对数(log2(arg) 或 lb(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
注意
对于整数 arg,二进制对数能转译成输入中最高位 1 的零底下标。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12.6.10 The log2 functions (第 179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.10 The log2 functions (第 381 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.10 The log2 functions (第 246 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.10 The log2 functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.10 The log2 functions (第 226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.10 The log2 functions (第 459 页)
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
| log2 的 C++ 文档 |
log2l
原址:https://zh.cppreference.com/w/c/numeric/math/log2
作用:计算底为 2 的对数({\small \log_{2}{x} }{\small \log_{2}{x} }log2(x)) (函数)
备注:
| |
1-3) 计算 arg 的底 2 对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 log2l。否则,若 arg 拥有整数类型或 double 类型,则调用 log2。否则调用 log2f。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的底 2 对数(log2(arg) 或 lb(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
注意
对于整数 arg,二进制对数能转译成输入中最高位 1 的零底下标。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12.6.10 The log2 functions (第 179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.10 The log2 functions (第 381 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.10 The log2 functions (第 246 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.10 The log2 functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.10 The log2 functions (第 226 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.10 The log2 functions (第 459 页)
参阅
| log logf (C99) logl (C99) | 计算自然对数(底为 e)(lnxlnx) (函数) |
|---|---|
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| exp2 (C99) exp2f (C99) exp2l (C99) | 计算 2 的给定次幂(2x2x) (函数) |
| log2 的 C++ 文档 |
logb
原址:https://zh.cppreference.com/w/c/numeric/math/logb
作用:提取给定数的指数(结果为浮点数) (函数)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为浮点数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 logbl。否则,若 arg 拥有整数类型或 double 类型,则调用 logb。否则调用 logbf。
正式而言,无偏指数是非零 arg 的 logr|arg| 的有符号整数部分(此函数作为浮点数返回),其中 r 是 FLT_RADIX。若 arg 为非正规,则当做它如同已正规化。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为有符号浮点数的 arg 的无偏指数。
若出现定义域错误,则返回实现定义值。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零则可能出现定义域或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。 - 若
arg为 ±∞,则返回 +∞。 - 若
arg为 NaN,则返回 NaN。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)且忽略当前舍入模式。
注解
POSIX 要求若 arg 为 ±0 则出现极点错误。
logb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 logb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
比较不同的浮点数分解函数。
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.11 The logb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.11 The logb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.11 The logb functions (第 179-180 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.11 The logb functions (第 381 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.11 The logb functions (第 246 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.11 The logb functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.11 The logb functions (第 227 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.11 The logb functions (第 459 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ilogb (C99) ilogbf (C99) ilogbl (C99) | 提取给定数的指数(结果为整数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| logb 的 C++ 文档 |
logbf
原址:https://zh.cppreference.com/w/c/numeric/math/logb
作用:提取给定数的指数(结果为浮点数) (函数)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为浮点数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 logbl。否则,若 arg 拥有整数类型或 double 类型,则调用 logb。否则调用 logbf。
正式而言,无偏指数是非零 arg 的 logr|arg| 的有符号整数部分(此函数作为浮点数返回),其中 r 是 FLT_RADIX。若 arg 为非正规,则当做它如同已正规化。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为有符号浮点数的 arg 的无偏指数。
若出现定义域错误,则返回实现定义值。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零则可能出现定义域或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。 - 若
arg为 ±∞,则返回 +∞。 - 若
arg为 NaN,则返回 NaN。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)且忽略当前舍入模式。
注解
POSIX 要求若 arg 为 ±0 则出现极点错误。
logb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 logb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
比较不同的浮点数分解函数。
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.11 The logb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.11 The logb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.11 The logb functions (第 179-180 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.11 The logb functions (第 381 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.11 The logb functions (第 246 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.11 The logb functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.11 The logb functions (第 227 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.11 The logb functions (第 459 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ilogb (C99) ilogbf (C99) ilogbl (C99) | 提取给定数的指数(结果为整数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| logb 的 C++ 文档 |
logbl
原址:https://zh.cppreference.com/w/c/numeric/math/logb
作用:提取给定数的指数(结果为浮点数) (函数)
备注:
| |
1-3) 从浮点数实参 arg 提取独立于基底的无偏指数,并将它作为浮点数返回。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 logbl。否则,若 arg 拥有整数类型或 double 类型,则调用 logb。否则调用 logbf。
正式而言,无偏指数是非零 arg 的 logr|arg| 的有符号整数部分(此函数作为浮点数返回),其中 r 是 FLT_RADIX。若 arg 为非正规,则当做它如同已正规化。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回作为有符号浮点数的 arg 的无偏指数。
若出现定义域错误,则返回实现定义值。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 为零则可能出现定义域或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。 - 若
arg为 ±∞,则返回 +∞。 - 若
arg为 NaN,则返回 NaN。 - 所有其他情况下,结果是准确的(决不引发 FE_INEXACT)且忽略当前舍入模式。
注解
POSIX 要求若 arg 为 ±0 则出现极点错误。
logb 所返回的指数值始终比 frexp 所返回的小 1,因为不同的正规化要求:对于 logb 返回的指数 e,|arg*r-e
| 在 1 与 r 之间(典型地在 1 与 2 之间),但 frexp 返回的指数 e,|arg*2-e
| 在 0.5 与 1 之间。
示例
比较不同的浮点数分解函数。
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.11 The logb functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.11 The logb functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.11 The logb functions (第 179-180 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.11 The logb functions (第 381 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.11 The logb functions (第 246 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.11 The logb functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.11 The logb functions (第 227 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.11 The logb functions (第 459 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ilogb (C99) ilogbf (C99) ilogbl (C99) | 提取给定数的指数(结果为整数) (函数) |
| scalbn (C99) scalbnf (C99) scalbnl (C99) scalbln (C99) scalblnf (C99) scalblnl (C99) | 高效计算一个数乘 FLT_RADIX 的幂 (函数) |
| logb 的 C++ 文档 |
logf
原址:https://zh.cppreference.com/w/c/numeric/math/log
作用:计算自然对数(底为 e)({\small \ln{x} }{\small \ln{x} }ln(x)) (函数)
备注:
| |
1-3) 计算 arg 的自然(底 e)对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 logl。否则,若 arg 拥有整数类型或 double 类型,则调用 log。否则,调用 logf。若 arg 为复数或序数,则宏调用对应的复数函数([clogf](http://zh.cppreference.com/w/c/numeric/complex/clog)、[clog](http://zh.cppreference.com/w/c/numeric/complex/clog)、[clogl](http://zh.cppreference.com/w/c/numeric/complex/clog))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的自然(底 e)对数(ln(arg) 或 loge(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.7 The log functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.7 The log functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.7 The log functions (第 178-179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.7 The log functions (第 380 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.7 The log functions (第 244-245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.7 The log functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.7 The log functions (第 225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.7 The log functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.4 The log function
参阅
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
|---|---|
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
| clog (C99) clogf (C99) clogl (C99) | 计算复数的自然对数 (函数) |
| log 的 C++ 文档 |
logl
原址:https://zh.cppreference.com/w/c/numeric/math/log
作用:计算自然对数(底为 e)({\small \ln{x} }{\small \ln{x} }ln(x)) (函数)
备注:
| |
1-3) 计算 arg 的自然(底 e)对数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 logl。否则,若 arg 拥有整数类型或 double 类型,则调用 log。否则,调用 logf。若 arg 为复数或序数,则宏调用对应的复数函数([clogf](http://zh.cppreference.com/w/c/numeric/complex/clog)、[clog](http://zh.cppreference.com/w/c/numeric/complex/clog)、[clogl](http://zh.cppreference.com/w/c/numeric/complex/clog))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的自然(底 e)对数(ln(arg) 或 loge(arg))。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误,则返回 -HUGE_VAL、-HUGE_VALF 或 -HUGE_VALL。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若 arg 为零则可能出现极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 -∞ 并引发 FE_DIVBYZERO。
- 若参数为 1,则返回 +0。
- 若参数为负数,则返回 NaN 并引发 FE_INVALID。
- 若参数为 +∞,则返回 +∞。
- 若参数为 NaN,则返回 NaN。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.7 The log functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.7 The log functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.7 The log functions (第 178-179 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.3.7 The log functions (第 380 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.7 The log functions (第 244-245 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.7 The log functions (第 522 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.7 The log functions (第 225 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.7 The log functions (第 459 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.4 The log function
参阅
| log10 log10f (C99) log10l (C99) | 计算常用对数 (底为 10)(log10xlog10x) (函数) |
|---|---|
| log2 (C99) log2f (C99) log2l (C99) | 计算底为 2 的对数(log2xlog2x) (函数) |
| log1p (C99) log1pf (C99) log1pl (C99) | 计算给定数加 1 的自然对数(底为 e)(ln(1+x)ln(1+x)) (函数) |
| exp expf (C99) expl (C99) | 计算 e 的给定次幂(exex) (函数) |
| clog (C99) clogf (C99) clogl (C99) | 计算复数的自然对数 (函数) |
| log 的 C++ 文档 |
lrint
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
lrintf
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
lrintl
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
lround
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
lroundf
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
lroundl
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
modf
原址:https://zh.cppreference.com/w/c/numeric/math/modf
作用:把一个数拆分成整数和小数部分 (函数)
备注:
| |
1-3) 分解给定的浮点数 arg 为整数和分数部分,每个都拥有与 arg 相同的类型和符号。(以浮点数格式)存储整数部分于 iptr 所指向的对象。
参数
| arg | - | 浮点数 |
|---|---|---|
| iptr | - | 指向要存储整数部分的目标的浮点数的指针 |
返回值
若不出现错误,则返回与 arg 相同符号的 arg 小数部分。将整数部分放进 iptr 所指向的值。
返回值和存储于 *iptr 的值的和给出 arg(允许舍入)。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回 ±0,并存储 ±0 于*iptr。 - 若
arg为 ±∞,则返回 ±0,并存储 ±∞ 于*iptr。 - 若
arg为 NaN,则返回 NaN,并存储 NaN 于*iptr。 - 返回值是准确的,忽略当前舍入模式。
注解
此函数表现为如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.12 The modf functions (第 TBD 页)
F.10.3.12 The modf functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.12 The modf functions (第 TBD 页)
F.10.3.12 The modf functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.12 The modf functions (第 246-247 页)
F.10.3.12 The modf functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.12 The modf functions (第 227 页)
F.9.3.12 The modf functions (第 460 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.6 The modf function
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| modf 的 C++ 文档 |
modff
原址:https://zh.cppreference.com/w/c/numeric/math/modf
作用:把一个数拆分成整数和小数部分 (函数)
备注:
| |
1-3) 分解给定的浮点数 arg 为整数和分数部分,每个都拥有与 arg 相同的类型和符号。(以浮点数格式)存储整数部分于 iptr 所指向的对象。
参数
| arg | - | 浮点数 |
|---|---|---|
| iptr | - | 指向要存储整数部分的目标的浮点数的指针 |
返回值
若不出现错误,则返回与 arg 相同符号的 arg 小数部分。将整数部分放进 iptr 所指向的值。
返回值和存储于 *iptr 的值的和给出 arg(允许舍入)。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回 ±0,并存储 ±0 于*iptr。 - 若
arg为 ±∞,则返回 ±0,并存储 ±∞ 于*iptr。 - 若
arg为 NaN,则返回 NaN,并存储 NaN 于*iptr。 - 返回值是准确的,忽略当前舍入模式。
注解
此函数表现为如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.12 The modf functions (第 TBD 页)
F.10.3.12 The modf functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.12 The modf functions (第 TBD 页)
F.10.3.12 The modf functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.12 The modf functions (第 246-247 页)
F.10.3.12 The modf functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.12 The modf functions (第 227 页)
F.9.3.12 The modf functions (第 460 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.6 The modf function
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| modf 的 C++ 文档 |
modfl
原址:https://zh.cppreference.com/w/c/numeric/math/modf
作用:把一个数拆分成整数和小数部分 (函数)
备注:
| |
1-3) 分解给定的浮点数 arg 为整数和分数部分,每个都拥有与 arg 相同的类型和符号。(以浮点数格式)存储整数部分于 iptr 所指向的对象。
参数
| arg | - | 浮点数 |
|---|---|---|
| iptr | - | 指向要存储整数部分的目标的浮点数的指针 |
返回值
若不出现错误,则返回与 arg 相同符号的 arg 小数部分。将整数部分放进 iptr 所指向的值。
返回值和存储于 *iptr 的值的和给出 arg(允许舍入)。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEE 浮点数算术(IEC 60559),则
- 若
arg为 ±0,则返回 ±0,并存储 ±0 于*iptr。 - 若
arg为 ±∞,则返回 ±0,并存储 ±∞ 于*iptr。 - 若
arg为 NaN,则返回 NaN,并存储 NaN 于*iptr。 - 返回值是准确的,忽略当前舍入模式。
注解
此函数表现为如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.12 The modf functions (第 TBD 页)
F.10.3.12 The modf functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.12 The modf functions (第 TBD 页)
F.10.3.12 The modf functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.12 The modf functions (第 246-247 页)
F.10.3.12 The modf functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.12 The modf functions (第 227 页)
F.9.3.12 The modf functions (第 460 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.4.6 The modf function
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| modf 的 C++ 文档 |
nan
原址:https://zh.cppreference.com/w/c/numeric/math/nan
作用:返回 NaN(非数) (函数)
备注:
| |
转换实现定义的字符串 arg 为对应的安静 NaN 值,分别如同以下列方式调用 strtod、strtof 或 strtold:
- 调用
nan("n-字符序列"),其中 n-字符序列 是数字、拉丁字母和下划线的序列,等价于调用*/\*strtoX\*/*("NAN(n-字符序列)", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。 - 调用
nan("")等价于调用*/\*strtoX\*/*("NAN()", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。 - 调用
nan("字符串"),其中字符串既非 n-字符序列 亦非空字符串,等价于调用*/\*strtoX\*/*("NAN", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。
1) 解析函数为 strtof。
2) 解析函数为 strtod。
3) 解析函数为 strtold。
4) 解析函数为 strtod32。
5) 解析函数为 strtod64。
6) 解析函数为 strtod128。
当且仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明返回十进制浮点数的各函数。 (C23 起)
参数
| arg | - | 标识 NaN 内容的窄字符串 |
|---|---|---|
返回值
对应标识字符串 arg 的安静 NaN 值,或若实现不支持安静 NaN 则为零。
若实现支持 IEEE 浮点数算术(IEC 60559),则它也支持安静 NaN。
错误处理
此函数不受制于任何指定于 <ath_errhandlin> 的错误条件。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12.11.2 The nan functions (第 186-187 页)
F.10.8.2 The nan functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.2 The nan functions (第 256 页)
F.10.8.2 The nan functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.2 The nan functions (第 237 页)
F.9.8.2 The fabs functions (第 465 页)
参阅
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
|---|---|
| NAN (C99) | 求值为 float 类型的安静 NaN (宏常量) |
| nanf, nan, nanl 的 C++ 文档 |
nanf
原址:https://zh.cppreference.com/w/c/numeric/math/nan
作用:返回 NaN(非数) (函数)
备注:
| |
转换实现定义的字符串 arg 为对应的安静 NaN 值,分别如同以下列方式调用 strtod、strtof 或 strtold:
- 调用
nan("n-字符序列"),其中 n-字符序列 是数字、拉丁字母和下划线的序列,等价于调用*/\*strtoX\*/*("NAN(n-字符序列)", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。 - 调用
nan("")等价于调用*/\*strtoX\*/*("NAN()", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。 - 调用
nan("字符串"),其中字符串既非 n-字符序列 亦非空字符串,等价于调用*/\*strtoX\*/*("NAN", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。
1) 解析函数为 strtof。
2) 解析函数为 strtod。
3) 解析函数为 strtold。
4) 解析函数为 strtod32。
5) 解析函数为 strtod64。
6) 解析函数为 strtod128。
当且仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明返回十进制浮点数的各函数。 (C23 起)
参数
| arg | - | 标识 NaN 内容的窄字符串 |
|---|---|---|
返回值
对应标识字符串 arg 的安静 NaN 值,或若实现不支持安静 NaN 则为零。
若实现支持 IEEE 浮点数算术(IEC 60559),则它也支持安静 NaN。
错误处理
此函数不受制于任何指定于 <ath_errhandlin> 的错误条件。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12.11.2 The nan functions (第 186-187 页)
F.10.8.2 The nan functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.2 The nan functions (第 256 页)
F.10.8.2 The nan functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.2 The nan functions (第 237 页)
F.9.8.2 The fabs functions (第 465 页)
参阅
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
|---|---|
| NAN (C99) | 求值为 float 类型的安静 NaN (宏常量) |
| nanf, nan, nanl 的 C++ 文档 |
nanl
原址:https://zh.cppreference.com/w/c/numeric/math/nan
作用:返回 NaN(非数) (函数)
备注:
| |
转换实现定义的字符串 arg 为对应的安静 NaN 值,分别如同以下列方式调用 strtod、strtof 或 strtold:
- 调用
nan("n-字符序列"),其中 n-字符序列 是数字、拉丁字母和下划线的序列,等价于调用*/\*strtoX\*/*("NAN(n-字符序列)", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。 - 调用
nan("")等价于调用*/\*strtoX\*/*("NAN()", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。 - 调用
nan("字符串"),其中字符串既非 n-字符序列 亦非空字符串,等价于调用*/\*strtoX\*/*("NAN", (char**)[NULL](http://zh.cppreference.com/w/c/types/NULL));。
1) 解析函数为 strtof。
2) 解析函数为 strtod。
3) 解析函数为 strtold。
4) 解析函数为 strtod32。
5) 解析函数为 strtod64。
6) 解析函数为 strtod128。
当且仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明返回十进制浮点数的各函数。 (C23 起)
参数
| arg | - | 标识 NaN 内容的窄字符串 |
|---|---|---|
返回值
对应标识字符串 arg 的安静 NaN 值,或若实现不支持安静 NaN 则为零。
若实现支持 IEEE 浮点数算术(IEC 60559),则它也支持安静 NaN。
错误处理
此函数不受制于任何指定于 <ath_errhandlin> 的错误条件。
示例
| |
可能的输出:
| |
引用
C17 标准(ISO/IEC 9899:2018):
7.12.11.2 The nan functions (第 186-187 页)
F.10.8.2 The nan functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.2 The nan functions (第 256 页)
F.10.8.2 The nan functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.2 The nan functions (第 237 页)
F.9.8.2 The fabs functions (第 465 页)
参阅
| isnan (C99) | 检查给定数是否为 NaN (宏函数) |
|---|---|
| NAN (C99) | 求值为 float 类型的安静 NaN (宏常量) |
| nanf, nan, nanl 的 C++ 文档 |
nearbyint
原址:https://zh.cppreference.com/w/c/numeric/math/nearbyint
作用:用当前舍入模式取整到整数 (函数)
备注:
| |
1-3) 以当前舍入模式,舍入浮点数实参 arg 到浮点数格式的整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 nearbyintl。否则,若 arg 拥有整数类型或 double 类型,则调用 nearbyint。否则调用 nearbyintf。
参数值
| arg | - | 浮点数 |
|---|---|---|
返回值
返回 arg 按照当前舍入模式的最接近整数。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT
- 若
arg为 ±∞,则返回不修改的参数 - 若
arg为 ±0,则返回不修改的参数 - 若
arg为 NaN,则返回 NaN
展开
nearbyint 和 rint 之间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是整数,故 nearbyint 自身决不溢出;然而存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为 FE_TONEAREST,则此函数在中点情况向偶数舍入(同 rint,但不同于 round)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.3 The nearbyint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.3 The nearbyint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.3 The nearbyint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.3 The nearbyint functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.3 The nearbyint functions (第 251-252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.3 The nearbyint functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.3 The nearbyint functions (第 232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.3 The nearbyint functions (第 463 页)
参阅
| rint (C99) rintf (C99) rintl (C99) lrint (C99) lrintf (C99) lrintl (C99) llrint (C99) llrintf (C99) llrintl (C99) | 使用当前舍入模式取整到整数,若结果有误则产生异常 (函数) |
|---|---|
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| nearbyint 的 C++ 文档 |
nearbyintf
原址:https://zh.cppreference.com/w/c/numeric/math/nearbyint
作用:用当前舍入模式取整到整数 (函数)
备注:
| |
1-3) 以当前舍入模式,舍入浮点数实参 arg 到浮点数格式的整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 nearbyintl。否则,若 arg 拥有整数类型或 double 类型,则调用 nearbyint。否则调用 nearbyintf。
参数值
| arg | - | 浮点数 |
|---|---|---|
返回值
返回 arg 按照当前舍入模式的最接近整数。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT
- 若
arg为 ±∞,则返回不修改的参数 - 若
arg为 ±0,则返回不修改的参数 - 若
arg为 NaN,则返回 NaN
展开
nearbyint 和 rint 之间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是整数,故 nearbyint 自身决不溢出;然而存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为 FE_TONEAREST,则此函数在中点情况向偶数舍入(同 rint,但不同于 round)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.3 The nearbyint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.3 The nearbyint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.3 The nearbyint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.3 The nearbyint functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.3 The nearbyint functions (第 251-252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.3 The nearbyint functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.3 The nearbyint functions (第 232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.3 The nearbyint functions (第 463 页)
参阅
| rint (C99) rintf (C99) rintl (C99) lrint (C99) lrintf (C99) lrintl (C99) llrint (C99) llrintf (C99) llrintl (C99) | 使用当前舍入模式取整到整数,若结果有误则产生异常 (函数) |
|---|---|
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| nearbyint 的 C++ 文档 |
nearbyintl
原址:https://zh.cppreference.com/w/c/numeric/math/nearbyint
作用:用当前舍入模式取整到整数 (函数)
备注:
| |
1-3) 以当前舍入模式,舍入浮点数实参 arg 到浮点数格式的整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 nearbyintl。否则,若 arg 拥有整数类型或 double 类型,则调用 nearbyint。否则调用 nearbyintf。
参数值
| arg | - | 浮点数 |
|---|---|---|
返回值
返回 arg 按照当前舍入模式的最接近整数。
错误处理
此函数不受制于任何指定于 math_errhandling 的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT
- 若
arg为 ±∞,则返回不修改的参数 - 若
arg为 ±0,则返回不修改的参数 - 若
arg为 NaN,则返回 NaN
展开
nearbyint 和 rint 之间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是整数,故 nearbyint 自身决不溢出;然而存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为 FE_TONEAREST,则此函数在中点情况向偶数舍入(同 rint,但不同于 round)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.3 The nearbyint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.3 The nearbyint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.3 The nearbyint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.3 The nearbyint functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.3 The nearbyint functions (第 251-252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.3 The nearbyint functions (第 526 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.3 The nearbyint functions (第 232 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.3 The nearbyint functions (第 463 页)
参阅
| rint (C99) rintf (C99) rintl (C99) lrint (C99) lrintf (C99) lrintl (C99) llrint (C99) llrintf (C99) llrintl (C99) | 使用当前舍入模式取整到整数,若结果有误则产生异常 (函数) |
|---|---|
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| nearbyint 的 C++ 文档 |
nextafter
原址:https://zh.cppreference.com/w/c/numeric/math/nextafter
作用:确定到给定值方向的下一个可表示的浮点数 (函数)
备注:
| |
1-3) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回 to。
4-6) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回从 long double 转换到函数返回类型的 to,而不带范围或精度的损失。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 nextafterl。否则,若任何实参拥有整数类型或 double 类型,则调用 nextafter。否则调用 nextafterf。
8) 泛型宏:若实参 from 拥有 long double 类型,则调用 nexttowardl。否则,若实参 from 拥有整数类型或 double 类型,则调用 nexttoward。否则调用 nexttowardf。
参数
| from, to | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 from 于 to 的方向的下个可表示值。若 from 等于 to,则返回 to,转换到函数的类型。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL(所带符号同 from)。
若出现下溢所致的值域错误,则返回正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
from有限,但期待的结果无限,则引发 FE_INEXACT 和 FE_OVERFLOW。 - 若
from不等于to且结果为非正规或零,则引发 FE_INEXACT 和 FE_UNDERFLOW。 - 任何情况下,返回值独立于当前舍入模式。
- 若
from或to为 NaN,则返回 NaN
注解
POSIX 指定上溢和下溢条件是值域错误(可以设置 errno)。
IEC 60559 推荐凡在 from == to 时均返回 from。但这些函数替而返回 to,这使得围绕零的行为一致:nextafter(-0.0, +0.0) 返回 +0.0 而 nextafter(+0.0, -0.0) 返回 –0.0。
nextafter 常通过操纵 IEEE 表示来实现(glibc)(musl)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.3 The nextafter functions (第 TBD 页)
7.12.11.4 The nexttoward functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.3 The nextafter functions (第 TBD 页)
F.10.8.4 The nexttoward functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.3 The nextafter functions (第 187 页)
7.12.11.4 The nexttoward functions (第 187 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.8.3 The nextafter functions (第 386 页)
F.10.8.4 The nexttoward functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.3 The nextafter functions (第 256 页)
7.12.11.4 The nexttoward functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.3 The nextafter functions (第 529 页)
F.10.8.4 The nexttoward functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.3 The nextafter functions (第 237 页)
7.12.11.4 The nexttoward functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.3 The nextafter functions (第 466 页)
F.9.8.4 The nexttoward functions (第 466 页)
参阅
nextafter 的 C++ 文档
nextafterf
原址:https://zh.cppreference.com/w/c/numeric/math/nextafter
作用:确定到给定值方向的下一个可表示的浮点数 (函数)
备注:
| |
1-3) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回 to。
4-6) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回从 long double 转换到函数返回类型的 to,而不带范围或精度的损失。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 nextafterl。否则,若任何实参拥有整数类型或 double 类型,则调用 nextafter。否则调用 nextafterf。
8) 泛型宏:若实参 from 拥有 long double 类型,则调用 nexttowardl。否则,若实参 from 拥有整数类型或 double 类型,则调用 nexttoward。否则调用 nexttowardf。
参数
| from, to | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 from 于 to 的方向的下个可表示值。若 from 等于 to,则返回 to,转换到函数的类型。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL(所带符号同 from)。
若出现下溢所致的值域错误,则返回正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
from有限,但期待的结果无限,则引发 FE_INEXACT 和 FE_OVERFLOW。 - 若
from不等于to且结果为非正规或零,则引发 FE_INEXACT 和 FE_UNDERFLOW。 - 任何情况下,返回值独立于当前舍入模式。
- 若
from或to为 NaN,则返回 NaN
注解
POSIX 指定上溢和下溢条件是值域错误(可以设置 errno)。
IEC 60559 推荐凡在 from == to 时均返回 from。但这些函数替而返回 to,这使得围绕零的行为一致:nextafter(-0.0, +0.0) 返回 +0.0 而 nextafter(+0.0, -0.0) 返回 –0.0。
nextafter 常通过操纵 IEEE 表示来实现(glibc)(musl)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.3 The nextafter functions (第 TBD 页)
7.12.11.4 The nexttoward functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.3 The nextafter functions (第 TBD 页)
F.10.8.4 The nexttoward functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.3 The nextafter functions (第 187 页)
7.12.11.4 The nexttoward functions (第 187 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.8.3 The nextafter functions (第 386 页)
F.10.8.4 The nexttoward functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.3 The nextafter functions (第 256 页)
7.12.11.4 The nexttoward functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.3 The nextafter functions (第 529 页)
F.10.8.4 The nexttoward functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.3 The nextafter functions (第 237 页)
7.12.11.4 The nexttoward functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.3 The nextafter functions (第 466 页)
F.9.8.4 The nexttoward functions (第 466 页)
参阅
nextafter 的 C++ 文档
nextafterl
原址:https://zh.cppreference.com/w/c/numeric/math/nextafter
作用:确定到给定值方向的下一个可表示的浮点数 (函数)
备注:
| |
1-3) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回 to。
4-6) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回从 long double 转换到函数返回类型的 to,而不带范围或精度的损失。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 nextafterl。否则,若任何实参拥有整数类型或 double 类型,则调用 nextafter。否则调用 nextafterf。
8) 泛型宏:若实参 from 拥有 long double 类型,则调用 nexttowardl。否则,若实参 from 拥有整数类型或 double 类型,则调用 nexttoward。否则调用 nexttowardf。
参数
| from, to | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 from 于 to 的方向的下个可表示值。若 from 等于 to,则返回 to,转换到函数的类型。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL(所带符号同 from)。
若出现下溢所致的值域错误,则返回正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
from有限,但期待的结果无限,则引发 FE_INEXACT 和 FE_OVERFLOW。 - 若
from不等于to且结果为非正规或零,则引发 FE_INEXACT 和 FE_UNDERFLOW。 - 任何情况下,返回值独立于当前舍入模式。
- 若
from或to为 NaN,则返回 NaN
注解
POSIX 指定上溢和下溢条件是值域错误(可以设置 errno)。
IEC 60559 推荐凡在 from == to 时均返回 from。但这些函数替而返回 to,这使得围绕零的行为一致:nextafter(-0.0, +0.0) 返回 +0.0 而 nextafter(+0.0, -0.0) 返回 –0.0。
nextafter 常通过操纵 IEEE 表示来实现(glibc)(musl)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.3 The nextafter functions (第 TBD 页)
7.12.11.4 The nexttoward functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.3 The nextafter functions (第 TBD 页)
F.10.8.4 The nexttoward functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.3 The nextafter functions (第 187 页)
7.12.11.4 The nexttoward functions (第 187 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.8.3 The nextafter functions (第 386 页)
F.10.8.4 The nexttoward functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.3 The nextafter functions (第 256 页)
7.12.11.4 The nexttoward functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.3 The nextafter functions (第 529 页)
F.10.8.4 The nexttoward functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.3 The nextafter functions (第 237 页)
7.12.11.4 The nexttoward functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.3 The nextafter functions (第 466 页)
F.9.8.4 The nexttoward functions (第 466 页)
参阅
nextafter 的 C++ 文档
nexttoward
原址:https://zh.cppreference.com/w/c/numeric/math/nextafter
作用:确定到给定值方向的下一个可表示的浮点数 (函数)
备注:
| |
1-3) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回 to。
4-6) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回从 long double 转换到函数返回类型的 to,而不带范围或精度的损失。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 nextafterl。否则,若任何实参拥有整数类型或 double 类型,则调用 nextafter。否则调用 nextafterf。
8) 泛型宏:若实参 from 拥有 long double 类型,则调用 nexttowardl。否则,若实参 from 拥有整数类型或 double 类型,则调用 nexttoward。否则调用 nexttowardf。
参数
| from, to | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 from 于 to 的方向的下个可表示值。若 from 等于 to,则返回 to,转换到函数的类型。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL(所带符号同 from)。
若出现下溢所致的值域错误,则返回正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
from有限,但期待的结果无限,则引发 FE_INEXACT 和 FE_OVERFLOW。 - 若
from不等于to且结果为非正规或零,则引发 FE_INEXACT 和 FE_UNDERFLOW。 - 任何情况下,返回值独立于当前舍入模式。
- 若
from或to为 NaN,则返回 NaN
注解
POSIX 指定上溢和下溢条件是值域错误(可以设置 errno)。
IEC 60559 推荐凡在 from == to 时均返回 from。但这些函数替而返回 to,这使得围绕零的行为一致:nextafter(-0.0, +0.0) 返回 +0.0 而 nextafter(+0.0, -0.0) 返回 –0.0。
nextafter 常通过操纵 IEEE 表示来实现(glibc)(musl)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.3 The nextafter functions (第 TBD 页)
7.12.11.4 The nexttoward functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.3 The nextafter functions (第 TBD 页)
F.10.8.4 The nexttoward functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.3 The nextafter functions (第 187 页)
7.12.11.4 The nexttoward functions (第 187 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.8.3 The nextafter functions (第 386 页)
F.10.8.4 The nexttoward functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.3 The nextafter functions (第 256 页)
7.12.11.4 The nexttoward functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.3 The nextafter functions (第 529 页)
F.10.8.4 The nexttoward functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.3 The nextafter functions (第 237 页)
7.12.11.4 The nexttoward functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.3 The nextafter functions (第 466 页)
F.9.8.4 The nexttoward functions (第 466 页)
参阅
nextafter 的 C++ 文档
nexttowardf
原址:https://zh.cppreference.com/w/c/numeric/math/nextafter
作用:确定到给定值方向的下一个可表示的浮点数 (函数)
备注:
| |
1-3) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回 to。
4-6) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回从 long double 转换到函数返回类型的 to,而不带范围或精度的损失。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 nextafterl。否则,若任何实参拥有整数类型或 double 类型,则调用 nextafter。否则调用 nextafterf。
8) 泛型宏:若实参 from 拥有 long double 类型,则调用 nexttowardl。否则,若实参 from 拥有整数类型或 double 类型,则调用 nexttoward。否则调用 nexttowardf。
参数
| from, to | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 from 于 to 的方向的下个可表示值。若 from 等于 to,则返回 to,转换到函数的类型。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL(所带符号同 from)。
若出现下溢所致的值域错误,则返回正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
from有限,但期待的结果无限,则引发 FE_INEXACT 和 FE_OVERFLOW。 - 若
from不等于to且结果为非正规或零,则引发 FE_INEXACT 和 FE_UNDERFLOW。 - 任何情况下,返回值独立于当前舍入模式。
- 若
from或to为 NaN,则返回 NaN
注解
POSIX 指定上溢和下溢条件是值域错误(可以设置 errno)。
IEC 60559 推荐凡在 from == to 时均返回 from。但这些函数替而返回 to,这使得围绕零的行为一致:nextafter(-0.0, +0.0) 返回 +0.0 而 nextafter(+0.0, -0.0) 返回 –0.0。
nextafter 常通过操纵 IEEE 表示来实现(glibc)(musl)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.3 The nextafter functions (第 TBD 页)
7.12.11.4 The nexttoward functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.3 The nextafter functions (第 TBD 页)
F.10.8.4 The nexttoward functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.3 The nextafter functions (第 187 页)
7.12.11.4 The nexttoward functions (第 187 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.8.3 The nextafter functions (第 386 页)
F.10.8.4 The nexttoward functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.3 The nextafter functions (第 256 页)
7.12.11.4 The nexttoward functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.3 The nextafter functions (第 529 页)
F.10.8.4 The nexttoward functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.3 The nextafter functions (第 237 页)
7.12.11.4 The nexttoward functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.3 The nextafter functions (第 466 页)
F.9.8.4 The nexttoward functions (第 466 页)
参阅
nextafter 的 C++ 文档
nexttowardl
原址:https://zh.cppreference.com/w/c/numeric/math/nextafter
作用:确定到给定值方向的下一个可表示的浮点数 (函数)
备注:
| |
1-3) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回 to。
4-6) 首先,转换两个实参为函数的类型,然后返回 from 于 to 方向的下个可表示值。若 from 等于 to,则返回从 long double 转换到函数返回类型的 to,而不带范围或精度的损失。
7) 泛型宏:若任何实参拥有 long double 类型,则调用 nextafterl。否则,若任何实参拥有整数类型或 double 类型,则调用 nextafter。否则调用 nextafterf。
8) 泛型宏:若实参 from 拥有 long double 类型,则调用 nexttowardl。否则,若实参 from 拥有整数类型或 double 类型,则调用 nexttoward。否则调用 nexttowardf。
参数
| from, to | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 from 于 to 的方向的下个可表示值。若 from 等于 to,则返回 to,转换到函数的类型。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL(所带符号同 from)。
若出现下溢所致的值域错误,则返回正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若
from有限,但期待的结果无限,则引发 FE_INEXACT 和 FE_OVERFLOW。 - 若
from不等于to且结果为非正规或零,则引发 FE_INEXACT 和 FE_UNDERFLOW。 - 任何情况下,返回值独立于当前舍入模式。
- 若
from或to为 NaN,则返回 NaN
注解
POSIX 指定上溢和下溢条件是值域错误(可以设置 errno)。
IEC 60559 推荐凡在 from == to 时均返回 from。但这些函数替而返回 to,这使得围绕零的行为一致:nextafter(-0.0, +0.0) 返回 +0.0 而 nextafter(+0.0, -0.0) 返回 –0.0。
nextafter 常通过操纵 IEEE 表示来实现(glibc)(musl)。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.11.3 The nextafter functions (第 TBD 页)
7.12.11.4 The nexttoward functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.8.3 The nextafter functions (第 TBD 页)
F.10.8.4 The nexttoward functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.11.3 The nextafter functions (第 187 页)
7.12.11.4 The nexttoward functions (第 187 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.8.3 The nextafter functions (第 386 页)
F.10.8.4 The nexttoward functions (第 386 页)
C11 标准(ISO/IEC 9899:2011):
7.12.11.3 The nextafter functions (第 256 页)
7.12.11.4 The nexttoward functions (第 257 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.8.3 The nextafter functions (第 529 页)
F.10.8.4 The nexttoward functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.11.3 The nextafter functions (第 237 页)
7.12.11.4 The nexttoward functions (第 238 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.8.3 The nextafter functions (第 466 页)
F.9.8.4 The nexttoward functions (第 466 页)
参阅
nextafter 的 C++ 文档
pow
原址:https://zh.cppreference.com/w/c/numeric/math/pow
作用:计算一个数的给定次幂(\small{x^y}\small{x^y}xy) (函数)
备注:
| |
1-3) 计算 base 的 exponent 次幂。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 powl。否则,若任何实参拥有整数类型或 double 类型,则调用 pow。否则调用 powf。若至少一个实参为复数或虚数,则宏调用对应的复函数([cpowf](http://zh.cppreference.com/w/c/numeric/complex/cpow)、[cpow](http://zh.cppreference.com/w/c/numeric/complex/cpow)、[cpowl](http://zh.cppreference.com/w/c/numeric/complex/cpow))。
参数
| base | - | 作为底的浮点数 |
|---|---|---|
| exponent | - | 作为指数的浮点数 |
返回值
若不出现错误,则返回 base 的 exponent 次幂(*baseexponent
*)。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误或上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 base 有限且为负,且 exponent 有限且为非整数,则出现定义域错误,并可能出现值域错误。
若 base 为零且 exponent 为零,则可能出现定义域错误。
若 base 为零且 exponent 为负,则可能出现定义域错误或极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
pow(+0, exponent),其中exponent为负奇数,返回+∞并引发 FE_DIVBYZEROpow(-0, exponent),其中exponent为负奇数,返回-∞并引发 FE_DIVBYZEROpow(±0, exponent),其中exponent为有限负数,且为偶数或非整数,则返回 +∞ 并引发 FE_DIVBYZEROpow(±0, -∞)返回 +∞ 并可能引发 FE_DIVBYZERO(C23 前)pow(+0, exponent),其中exponent为正奇数,返回 +0pow(-0, exponent),其中exponent为正奇数,返回 -0pow(±0, exponent),其中exponent为正非整数或正偶数,返回 +0pow(-1, ±∞)返回1pow(+1, exponent)对于任何exponent返回1,即使exponent为NaNpow(base, ±0)对于任何base返回1,即使base为NaNpow(base, exponent)返回NaN并引发 FE_INVALID,若base为有限负数且exponent为有限非整数。pow(base, -∞)对任何|base|<1返回 +∞pow(base, -∞)对任何|base|>1返回 +0pow(base, +∞)对任何|base|<1返回 +0pow(base, +∞)对任何|base|>1返回 +∞pow(-∞, exponent)返回 -0,若exponent为负奇整数pow(-∞, exponent)返回 +0,若exponent为负非整数或负偶数pow(-∞, exponent)返回 -∞,若exponent为正奇整数pow(-∞, exponent)返回 +∞,若exponent为正非整数或正偶数pow(+∞, exponent)对任何exponent返回 +0pow(+∞, exponent)对任何exponent返回 +∞- 除了指定于上处,若任何实参为 NaN,则返回 NaN
注解
尽管 pow 不能获得负数的开方根,也为 exponent 为 1 / 3 的常用情况提供了 cbrt 。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.5 The pow functions
7.27 Type-generic math <tgmath.h>
F.10.4.5 The pow functions (第 524-525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.4 The pow functions (第 248-249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.4 The pow functions (第 524-525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.4 The pow functions (第 248-249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.4 The pow functions (第 524-525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.4 The pow functions (第 229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.4 The pow functions (第 461 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.5.1 The pow function
参阅
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
|---|---|
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| cpow (C99) cpowf (C99) cpowl (C99) | 计算复数幂函数 (函数) |
| pow 的 C++ 文档 |
powf
原址:https://zh.cppreference.com/w/c/numeric/math/pow
作用:计算一个数的给定次幂(\small{x^y}\small{x^y}xy) (函数)
备注:
| |
1-3) 计算 base 的 exponent 次幂。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 powl。否则,若任何实参拥有整数类型或 double 类型,则调用 pow。否则调用 powf。若至少一个实参为复数或虚数,则宏调用对应的复函数([cpowf](http://zh.cppreference.com/w/c/numeric/complex/cpow)、[cpow](http://zh.cppreference.com/w/c/numeric/complex/cpow)、[cpowl](http://zh.cppreference.com/w/c/numeric/complex/cpow))。
参数
| base | - | 作为底的浮点数 |
|---|---|---|
| exponent | - | 作为指数的浮点数 |
返回值
若不出现错误,则返回 base 的 exponent 次幂(*baseexponent
*)。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误或上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 base 有限且为负,且 exponent 有限且为非整数,则出现定义域错误,并可能出现值域错误。
若 base 为零且 exponent 为零,则可能出现定义域错误。
若 base 为零且 exponent 为负,则可能出现定义域错误或极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
pow(+0, exponent),其中exponent为负奇数,返回+∞并引发 FE_DIVBYZEROpow(-0, exponent),其中exponent为负奇数,返回-∞并引发 FE_DIVBYZEROpow(±0, exponent),其中exponent为有限负数,且为偶数或非整数,则返回 +∞ 并引发 FE_DIVBYZEROpow(±0, -∞)返回 +∞ 并可能引发 FE_DIVBYZERO(C23 前)pow(+0, exponent),其中exponent为正奇数,返回 +0pow(-0, exponent),其中exponent为正奇数,返回 -0pow(±0, exponent),其中exponent为正非整数或正偶数,返回 +0pow(-1, ±∞)返回1pow(+1, exponent)对于任何exponent返回1,即使exponent为NaNpow(base, ±0)对于任何base返回1,即使base为NaNpow(base, exponent)返回NaN并引发 FE_INVALID,若base为有限负数且exponent为有限非整数。pow(base, -∞)对任何|base|<1返回 +∞pow(base, -∞)对任何|base|>1返回 +0pow(base, +∞)对任何|base|<1返回 +0pow(base, +∞)对任何|base|>1返回 +∞pow(-∞, exponent)返回 -0,若exponent为负奇整数pow(-∞, exponent)返回 +0,若exponent为负非整数或负偶数pow(-∞, exponent)返回 -∞,若exponent为正奇整数pow(-∞, exponent)返回 +∞,若exponent为正非整数或正偶数pow(+∞, exponent)对任何exponent返回 +0pow(+∞, exponent)对任何exponent返回 +∞- 除了指定于上处,若任何实参为 NaN,则返回 NaN
注解
尽管 pow 不能获得负数的开方根,也为 exponent 为 1 / 3 的常用情况提供了 cbrt 。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.5 The pow functions
7.27 Type-generic math <tgmath.h>
F.10.4.5 The pow functions (第 524-525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.4 The pow functions (第 248-249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.4 The pow functions (第 524-525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.4 The pow functions (第 248-249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.4 The pow functions (第 524-525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.4 The pow functions (第 229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.4 The pow functions (第 461 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.5.1 The pow function
参阅
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
|---|---|
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| cpow (C99) cpowf (C99) cpowl (C99) | 计算复数幂函数 (函数) |
| pow 的 C++ 文档 |
powl
原址:https://zh.cppreference.com/w/c/numeric/math/pow
作用:计算一个数的给定次幂(\small{x^y}\small{x^y}xy) (函数)
备注:
| |
1-3) 计算 base 的 exponent 次幂。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 powl。否则,若任何实参拥有整数类型或 double 类型,则调用 pow。否则调用 powf。若至少一个实参为复数或虚数,则宏调用对应的复函数([cpowf](http://zh.cppreference.com/w/c/numeric/complex/cpow)、[cpow](http://zh.cppreference.com/w/c/numeric/complex/cpow)、[cpowl](http://zh.cppreference.com/w/c/numeric/complex/cpow))。
参数
| base | - | 作为底的浮点数 |
|---|---|---|
| exponent | - | 作为指数的浮点数 |
返回值
若不出现错误,则返回 base 的 exponent 次幂(*baseexponent
*)。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现极点错误或上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 base 有限且为负,且 exponent 有限且为非整数,则出现定义域错误,并可能出现值域错误。
若 base 为零且 exponent 为零,则可能出现定义域错误。
若 base 为零且 exponent 为负,则可能出现定义域错误或极点错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
pow(+0, exponent),其中exponent为负奇数,返回+∞并引发 FE_DIVBYZEROpow(-0, exponent),其中exponent为负奇数,返回-∞并引发 FE_DIVBYZEROpow(±0, exponent),其中exponent为有限负数,且为偶数或非整数,则返回 +∞ 并引发 FE_DIVBYZEROpow(±0, -∞)返回 +∞ 并可能引发 FE_DIVBYZERO(C23 前)pow(+0, exponent),其中exponent为正奇数,返回 +0pow(-0, exponent),其中exponent为正奇数,返回 -0pow(±0, exponent),其中exponent为正非整数或正偶数,返回 +0pow(-1, ±∞)返回1pow(+1, exponent)对于任何exponent返回1,即使exponent为NaNpow(base, ±0)对于任何base返回1,即使base为NaNpow(base, exponent)返回NaN并引发 FE_INVALID,若base为有限负数且exponent为有限非整数。pow(base, -∞)对任何|base|<1返回 +∞pow(base, -∞)对任何|base|>1返回 +0pow(base, +∞)对任何|base|<1返回 +0pow(base, +∞)对任何|base|>1返回 +∞pow(-∞, exponent)返回 -0,若exponent为负奇整数pow(-∞, exponent)返回 +0,若exponent为负非整数或负偶数pow(-∞, exponent)返回 -∞,若exponent为正奇整数pow(-∞, exponent)返回 +∞,若exponent为正非整数或正偶数pow(+∞, exponent)对任何exponent返回 +0pow(+∞, exponent)对任何exponent返回 +∞- 除了指定于上处,若任何实参为 NaN,则返回 NaN
注解
尽管 pow 不能获得负数的开方根,也为 exponent 为 1 / 3 的常用情况提供了 cbrt 。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.5 The pow functions
7.27 Type-generic math <tgmath.h>
F.10.4.5 The pow functions (第 524-525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.4 The pow functions (第 248-249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.4 The pow functions (第 524-525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.4 The pow functions (第 248-249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.4 The pow functions (第 524-525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.4 The pow functions (第 229 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.4 The pow functions (第 461 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.5.1 The pow function
参阅
| sqrt sqrtf (C99) sqrtl (C99) | 计算平方根(√xx) (函数) |
|---|---|
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| cpow (C99) cpowf (C99) cpowl (C99) | 计算复数幂函数 (函数) |
| pow 的 C++ 文档 |
remainder
原址:https://zh.cppreference.com/w/c/numeric/math/remainder
作用:计算浮点数除法运算的带符号余数 (函数)
备注:
| |
1-3) 计算浮点数除法运算 x/y 的 IEEE 余数。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 remainderl。否则若任何实参拥有整数类型或 double 类型,则调用 remainder。否则调用 remainderf。
此函数所计算的除法运算 x/y 的 IEEE 浮点数余数,准确地为值 x - n * y,其中值 n 是最接近 x/y 准确值的整数。|n-x/y| = ½ 时,选择作为偶数的 n。
与 std::fmod() 相反,不保证返回值拥有与 x 相同的符号。
若返回值是 0,则它拥有与 x 相同的符号。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回如上定义的除法 x / y 的 IEEE 浮点数余数。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回正确结果。
若 y 为零但不出现定义域错误,则返回零。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 决不引发 FE_INEXACT,结果始终准确。
- 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若任一实参为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
fmod,但不是 remainder,适于安静地包装浮点数类型到无符号整数类型:(0.0 <= (y = [fmod](http://zh.cppreference.com/w/c/numeric/math/fmod)( [rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0 )) ? y : 65536.0 + y) 在范围 [``-0.0``, ``65535.0``] 内,它对应 unsigned short,但 remainder([rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0) 在范围 [``-32767.0``, ``+32768.0``] 内,它在 signed short 的范围外。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.2 The remainder functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.2 The remainder functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.2 The remainder functions (第 185-186 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.7.2 The remainder functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.2 The remainder functions (第 254-255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.2 The remainder functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.2 The remainder functions (第 235 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.2 The remainder functions (第 465 页)
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| fmod fmodf (C99) fmodl (C99) | 计算浮点数除法运算的余数 (函数) |
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| remainder 的 C++ 文档 |
remainderf
原址:https://zh.cppreference.com/w/c/numeric/math/remainder
作用:计算浮点数除法运算的带符号余数 (函数)
备注:
| |
1-3) 计算浮点数除法运算 x/y 的 IEEE 余数。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 remainderl。否则若任何实参拥有整数类型或 double 类型,则调用 remainder。否则调用 remainderf。
此函数所计算的除法运算 x/y 的 IEEE 浮点数余数,准确地为值 x - n * y,其中值 n 是最接近 x/y 准确值的整数。|n-x/y| = ½ 时,选择作为偶数的 n。
与 std::fmod() 相反,不保证返回值拥有与 x 相同的符号。
若返回值是 0,则它拥有与 x 相同的符号。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回如上定义的除法 x / y 的 IEEE 浮点数余数。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回正确结果。
若 y 为零但不出现定义域错误,则返回零。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 决不引发 FE_INEXACT,结果始终准确。
- 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若任一实参为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
fmod,但不是 remainder,适于安静地包装浮点数类型到无符号整数类型:(0.0 <= (y = [fmod](http://zh.cppreference.com/w/c/numeric/math/fmod)( [rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0 )) ? y : 65536.0 + y) 在范围 [``-0.0``, ``65535.0``] 内,它对应 unsigned short,但 remainder([rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0) 在范围 [``-32767.0``, ``+32768.0``] 内,它在 signed short 的范围外。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.2 The remainder functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.2 The remainder functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.2 The remainder functions (第 185-186 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.7.2 The remainder functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.2 The remainder functions (第 254-255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.2 The remainder functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.2 The remainder functions (第 235 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.2 The remainder functions (第 465 页)
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| fmod fmodf (C99) fmodl (C99) | 计算浮点数除法运算的余数 (函数) |
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| remainder 的 C++ 文档 |
remainderl
原址:https://zh.cppreference.com/w/c/numeric/math/remainder
作用:计算浮点数除法运算的带符号余数 (函数)
备注:
| |
1-3) 计算浮点数除法运算 x/y 的 IEEE 余数。
4) 泛型宏:若任何实参拥有 long double 类型,则调用 remainderl。否则若任何实参拥有整数类型或 double 类型,则调用 remainder。否则调用 remainderf。
此函数所计算的除法运算 x/y 的 IEEE 浮点数余数,准确地为值 x - n * y,其中值 n 是最接近 x/y 准确值的整数。|n-x/y| = ½ 时,选择作为偶数的 n。
与 std::fmod() 相反,不保证返回值拥有与 x 相同的符号。
若返回值是 0,则它拥有与 x 相同的符号。
参数
| x, y | - | 浮点数 |
|---|---|---|
返回值
若成功,则返回如上定义的除法 x / y 的 IEEE 浮点数余数。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则返回正确结果。
若 y 为零但不出现定义域错误,则返回零。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 决不引发 FE_INEXACT,结果始终准确。
- 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若任一实参为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
fmod,但不是 remainder,适于安静地包装浮点数类型到无符号整数类型:(0.0 <= (y = [fmod](http://zh.cppreference.com/w/c/numeric/math/fmod)( [rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0 )) ? y : 65536.0 + y) 在范围 [``-0.0``, ``65535.0``] 内,它对应 unsigned short,但 remainder([rint](http://zh.cppreference.com/w/c/numeric/math/rint)(x), 65536.0) 在范围 [``-32767.0``, ``+32768.0``] 内,它在 signed short 的范围外。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.2 The remainder functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.2 The remainder functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.2 The remainder functions (第 185-186 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.7.2 The remainder functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.2 The remainder functions (第 254-255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.2 The remainder functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.2 The remainder functions (第 235 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.2 The remainder functions (第 465 页)
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| fmod fmodf (C99) fmodl (C99) | 计算浮点数除法运算的余数 (函数) |
| remquo (C99) remquof (C99) remquol (C99) | 计算除法运算的带符号余数,以及商的后三位 (函数) |
| remainder 的 C++ 文档 |
remquo
原址:https://zh.cppreference.com/w/c/numeric/math/remquo
作用:计算除法运算的带符号余数,以及商的后三位 (函数)
备注:
| |
1-3) 计算除法运算 x/y 的浮点数余数,如 remainder() 函数所为。另外,将存储 x/y 的至少最低三位及符号于 quo,这足以确定结果在周期中的八分位。
4) 泛型宏:若任何非指针实参拥有 long double 类型,则调用 remquol。否则,若任何非指针实参拥有整数类型或 double 类型,则调用 remquo。否则,调用 remquof。
参数
| x, y | - | 浮点数 |
|---|---|---|
| quo | - | 指向存储 x/y 的符号和某些位的整数的指针 |
返回值
若成功,则返回定义于 remainder 的 x/y 的余数,并存储 x/y 的符号和至少后三位有效数字于 *quo(正式而言,存储的值的符号是 x/y 的符号,而绝对值与 x/y 的整数商的绝对值对于 *modulo 2n
* 同余,其中 n 是实现定义的大于或等于 3 的整数)。
若 y 为零,则存储于 *quo 的值未指定。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则若支持非正规值则返回正确结果。
若 y 为零,但不出现定义域错误,则返回零。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 决不引发 FE_INEXACT。
- 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
x或y为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
此函数在实现可准确表示为浮点数的周期函数时有用:对非常大的 x 计算 sin(πx) 时,直接调用 sin 可能导致巨大误差,但若首先以 remquo 减小实参,则商的低位可用来确定结果在周期中的八分位,同时余数可用来计算拥有高精度的值。
某些平台上硬件支持此运算(而例如在 Intel CPU 上,FPREM1 在完成时于商中准确保留 3 位精度)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.3 The remquo functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.3 The remquo functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.3 The remquo functions (第 186 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.7.3 The remquo functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.3 The remquo functions (第 255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.3 The remquo functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.3 The remquo functions (第 236 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.3 The remquo functions (第 465 页)
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| fmod fmodf (C99) fmodl (C99) | 计算浮点数除法运算的余数 (函数) |
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
| remquo 的 C++ 文档 |
remquof
原址:https://zh.cppreference.com/w/c/numeric/math/remquo
作用:计算除法运算的带符号余数,以及商的后三位 (函数)
备注:
| |
1-3) 计算除法运算 x/y 的浮点数余数,如 remainder() 函数所为。另外,将存储 x/y 的至少最低三位及符号于 quo,这足以确定结果在周期中的八分位。
4) 泛型宏:若任何非指针实参拥有 long double 类型,则调用 remquol。否则,若任何非指针实参拥有整数类型或 double 类型,则调用 remquo。否则,调用 remquof。
参数
| x, y | - | 浮点数 |
|---|---|---|
| quo | - | 指向存储 x/y 的符号和某些位的整数的指针 |
返回值
若成功,则返回定义于 remainder 的 x/y 的余数,并存储 x/y 的符号和至少后三位有效数字于 *quo(正式而言,存储的值的符号是 x/y 的符号,而绝对值与 x/y 的整数商的绝对值对于 *modulo 2n
* 同余,其中 n 是实现定义的大于或等于 3 的整数)。
若 y 为零,则存储于 *quo 的值未指定。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则若支持非正规值则返回正确结果。
若 y 为零,但不出现定义域错误,则返回零。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 决不引发 FE_INEXACT。
- 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
x或y为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
此函数在实现可准确表示为浮点数的周期函数时有用:对非常大的 x 计算 sin(πx) 时,直接调用 sin 可能导致巨大误差,但若首先以 remquo 减小实参,则商的低位可用来确定结果在周期中的八分位,同时余数可用来计算拥有高精度的值。
某些平台上硬件支持此运算(而例如在 Intel CPU 上,FPREM1 在完成时于商中准确保留 3 位精度)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.3 The remquo functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.3 The remquo functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.3 The remquo functions (第 186 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.7.3 The remquo functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.3 The remquo functions (第 255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.3 The remquo functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.3 The remquo functions (第 236 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.3 The remquo functions (第 465 页)
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| fmod fmodf (C99) fmodl (C99) | 计算浮点数除法运算的余数 (函数) |
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
| remquo 的 C++ 文档 |
remquol
原址:https://zh.cppreference.com/w/c/numeric/math/remquo
作用:计算除法运算的带符号余数,以及商的后三位 (函数)
备注:
| |
1-3) 计算除法运算 x/y 的浮点数余数,如 remainder() 函数所为。另外,将存储 x/y 的至少最低三位及符号于 quo,这足以确定结果在周期中的八分位。
4) 泛型宏:若任何非指针实参拥有 long double 类型,则调用 remquol。否则,若任何非指针实参拥有整数类型或 double 类型,则调用 remquo。否则,调用 remquof。
参数
| x, y | - | 浮点数 |
|---|---|---|
| quo | - | 指向存储 x/y 的符号和某些位的整数的指针 |
返回值
若成功,则返回定义于 remainder 的 x/y 的余数,并存储 x/y 的符号和至少后三位有效数字于 *quo(正式而言,存储的值的符号是 x/y 的符号,而绝对值与 x/y 的整数商的绝对值对于 *modulo 2n
* 同余,其中 n 是实现定义的大于或等于 3 的整数)。
若 y 为零,则存储于 *quo 的值未指定。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现下溢所致的值域错误,则若支持非正规值则返回正确结果。
若 y 为零,但不出现定义域错误,则返回零。
错误处理
报告 math_errhandling 中指定的错误。
若 y 为零则可能出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 决不引发 FE_INEXACT。
- 若
x为 ±∞ 且y非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
y为 ±0 且x非 NaN,则返回 NaN 并引发 FE_INVALID。 - 若
x或y为 NaN,则返回 NaN。
注解
POSIX 要求若 x 为无穷大或 y 为零则出现定义域错误。
此函数在实现可准确表示为浮点数的周期函数时有用:对非常大的 x 计算 sin(πx) 时,直接调用 sin 可能导致巨大误差,但若首先以 remquo 减小实参,则商的低位可用来确定结果在周期中的八分位,同时余数可用来计算拥有高精度的值。
某些平台上硬件支持此运算(而例如在 Intel CPU 上,FPREM1 在完成时于商中准确保留 3 位精度)。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.10.3 The remquo functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.7.3 The remquo functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.10.3 The remquo functions (第 186 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.7.3 The remquo functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.10.3 The remquo functions (第 255 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.7.3 The remquo functions (第 529 页)
C99 标准(ISO/IEC 9899:1999):
7.12.10.3 The remquo functions (第 236 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.7.3 The remquo functions (第 465 页)
参阅
| div ldiv lldiv (C99) | 计算整数除法的商和余数 (函数) |
|---|---|
| fmod fmodf (C99) fmodl (C99) | 计算浮点数除法运算的余数 (函数) |
| remainder (C99) remainderf (C99) remainderl (C99) | 计算浮点数除法运算的带符号余数 (函数) |
| remquo 的 C++ 文档 |
rint
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
rintf
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
rintl
原址:https://zh.cppreference.com/w/c/numeric/math/rint
作用:使用当前舍入模式取整到整数,若结果有误则产生异常 (函数)
备注:
| |
1-3) 用当前舍入模式,舍入浮点数实参 arg 为整数(以浮点数格式)。
5-7, 9-11) 用当前舍入模式,舍入浮点数实参 arg 为整数。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则调用 rintl、lrintl、llrintl。否则若 arg 拥有整数或 double 类型,则调用 rint、lrint、llrint。否则分别调用 rintf、lrintf、llrintf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则为 arg 按照当前舍入模式的最接近整数。
错误处理
报告 math_errhandling 中指定的错误。
若 lrint 或 llrint 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
若
arg为 ±∞,则返回未修改的实参若
arg为 ±0,则返回未修改的实参若
arg为 NaN,则返回 NaN若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值若舍入结果在返回类型范围外,则引发 FE_INVALID 并返回实现定义值
若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值
注解
POSIX 指定 lrint 或 llrint 引发 FE_INEXACT 的所有情况都是定义域错误。
如 math_errhandling 所指定,rint 在舍入非整数有限值时可以(但不在非 IEEE 浮点数平台上要求)引发 FE_INEXACT。
rint 和 nearbyint 间仅有的区别是 nearbyint 决不引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数都是准确的整数,故 rint 自身决不上溢;然而在存储结果于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
若当前舍入模式为……
- FE_DOWNWARD,则
rint等价于 floor。 - FE_UPWARD,则
rint等价于 ceil。 - FE_TOWARDZERO,则
rint等价于 trunc。 - FE_TONEAREST,则
rint在中点情况和 round 的区别是前者始终舍入到偶数,而非远离零。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.4 The rint functions (第 TBD 页)
7.12.9.5 The lrint and llrint functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.4 The rint functions (第 TBD 页)
F.10.6.5 The lrint and llrint functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.4 The rint functions (第 184 页)
7.12.9.5 The lrint and llrint functions (第 184 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.4 The rint functions (第 384 页)
F.10.6.5 The lrint and llrint functions (第 384 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.4 The rint functions (第 252 页)
7.12.9.5 The lrint and llrint functions (第 252 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.4 The rint functions (第 527 页)
F.10.6.5 The lrint and llrint functions (第 527 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.4 The rint functions (第 232-233 页)
7.12.9.5 The lrint and llrint functions (第 233 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.4 The rint functions (第 463 页)
F.9.6.5 The lrint and llrint functions (第 463 页)
参阅
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
|---|---|
| nearbyint (C99) nearbyintf (C99) nearbyintl (C99) | 用当前舍入模式取整到整数 (函数) |
| fegetround (C99) fesetround (C99) | 获得或设置数字的舍入方向 (函数) |
| rint 的 C++ 文档 |
round
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
roundf
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
roundl
原址:https://zh.cppreference.com/w/c/numeric/math/round
作用:取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数)
备注:
| |
1-3) 计算与 arg 最邻近的整数(以浮点数格式),中点情况取远离零者,无关乎当前舍入模式。
5-7, 9-11) 计算与 arg 最邻近的整数(以整数格式),中点情况取远离零者,无关乎当前舍入模式。
4,8,12) 泛型宏:若 arg 拥有 long double 类型,则分别调用 roundl、lroundl、llroundl。否则,若 arg 拥有整数类型或 double 类型,则分别调用 round、lround、llround。否则分别调用 roundf、lroundf、llroundf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则与返回 arg 的最邻近整数,中点情况取远离零者,
返回值
实参
若出现定义域错误,则返回实现定义值。
错误处理
报告 math_errhandling 中指定的错误。
若 lround 或 llround 的结果在返回类型的可表示范围外,则可能出现定义域错误或值域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的该值。 - 若
arg为 ±0,则返回未修改的该值。 - 若
arg为 NaN,则返回 NaN。 - 决不引发 FE_INEXACT。
- 当前舍入模式无效。
- 若
arg为 ±∞,则引发 FE_INVALID 并返回实现定义值。 - 若舍入结果在返回类型的范围外,则引发 FE_INVALID 并返回实现定义值。
- 若
arg为 NaN,则引发 FE_INVALID 并返回实现定义值。
注解
round 在舍入非整数有限值时,可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故 round 自身决不上溢;然而在存储于整数对象时,结果可能溢出任何整数类型(包含 intmax_t)。
POSIX 指定 lround 或 llround 引发 FE_INEXACT 的所有情况都是定义域错误。
round 的 double 版本如同实现如下:
| |
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.9.6 The round functions (第 TBD 页)
7.12.9.7 The lround and llround functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.6.6 The round functions (第 TBD 页)
F.10.6.7 The lround and llround functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.9.6 The round functions (第 184 页)
7.12.9.7 The lround and llround functions (第 184-185 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.6.6 The round functions (第 384 页)
F.10.6.7 The lround and llround functions (第 385 页)
C11 标准(ISO/IEC 9899:2011):
7.12.9.6 The round functions (第 253 页)
7.12.9.7 The lround and llround functions (第 253 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.6 The round functions (第 527 页)
F.10.6.7 The lround and llround functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.6 The round functions (第 233 页)
7.12.9.7 The lround and llround functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.6 The round functions (第 464 页)
F.9.6.7 The lround and llround functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| trunc (C99) truncf (C99) truncl (C99) | 取整到绝对值不大于给定值的最接近整数 (函数) |
| round 的 C++ 文档 |
scalbln
原址:https://zh.cppreference.com/w/c/numeric/math/scalbn
作用:高效计算一个数乘 FLT_RADIX 的幂 (函数)
备注:
| |
1-3,5-7) 将浮点数 arg 乘以 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4,8) 泛型宏:若 arg 拥有 long double 类型,则调用 scalbnl 或 scalblnl。否则,若 arg 拥有整数类型或 double 类型,则调用 scalbn 或 scalbln。否则调用 scalbnf 或 scalblnf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×FLT_RADIXexp
*)。
若出现上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),scalbn 等价于 ldexp。
尽管指定 scalbn 和 scalbln 高效进行运算,多数实现上它们的效率仍低于用算术运算符乘或除以二的幂。
提供 scalbln 函数,因为从最小正浮点数放大到最大正有限值的因子可能大于标准保证的 INT_MAX 32767。特别是对于 80 位 long double,因子是 32828。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.13 The scalbn functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.13 The scalbn functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.13 The scalbn functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.13 The scalbn functions (第 460 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
| scalbn 的 C++ 文档 |
scalblnf
原址:https://zh.cppreference.com/w/c/numeric/math/scalbn
作用:高效计算一个数乘 FLT_RADIX 的幂 (函数)
备注:
| |
1-3,5-7) 将浮点数 arg 乘以 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4,8) 泛型宏:若 arg 拥有 long double 类型,则调用 scalbnl 或 scalblnl。否则,若 arg 拥有整数类型或 double 类型,则调用 scalbn 或 scalbln。否则调用 scalbnf 或 scalblnf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×FLT_RADIXexp
*)。
若出现上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),scalbn 等价于 ldexp。
尽管指定 scalbn 和 scalbln 高效进行运算,多数实现上它们的效率仍低于用算术运算符乘或除以二的幂。
提供 scalbln 函数,因为从最小正浮点数放大到最大正有限值的因子可能大于标准保证的 INT_MAX 32767。特别是对于 80 位 long double,因子是 32828。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.13 The scalbn functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.13 The scalbn functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.13 The scalbn functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.13 The scalbn functions (第 460 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
| scalbn 的 C++ 文档 |
scalblnl
原址:https://zh.cppreference.com/w/c/numeric/math/scalbn
作用:高效计算一个数乘 FLT_RADIX 的幂 (函数)
备注:
| |
1-3,5-7) 将浮点数 arg 乘以 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4,8) 泛型宏:若 arg 拥有 long double 类型,则调用 scalbnl 或 scalblnl。否则,若 arg 拥有整数类型或 double 类型,则调用 scalbn 或 scalbln。否则调用 scalbnf 或 scalblnf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×FLT_RADIXexp
*)。
若出现上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),scalbn 等价于 ldexp。
尽管指定 scalbn 和 scalbln 高效进行运算,多数实现上它们的效率仍低于用算术运算符乘或除以二的幂。
提供 scalbln 函数,因为从最小正浮点数放大到最大正有限值的因子可能大于标准保证的 INT_MAX 32767。特别是对于 80 位 long double,因子是 32828。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.13 The scalbn functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.13 The scalbn functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.13 The scalbn functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.13 The scalbn functions (第 460 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
| scalbn 的 C++ 文档 |
scalbn
原址:https://zh.cppreference.com/w/c/numeric/math/scalbn
作用:高效计算一个数乘 FLT_RADIX 的幂 (函数)
备注:
| |
1-3,5-7) 将浮点数 arg 乘以 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4,8) 泛型宏:若 arg 拥有 long double 类型,则调用 scalbnl 或 scalblnl。否则,若 arg 拥有整数类型或 double 类型,则调用 scalbn 或 scalbln。否则调用 scalbnf 或 scalblnf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×FLT_RADIXexp
*)。
若出现上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),scalbn 等价于 ldexp。
尽管指定 scalbn 和 scalbln 高效进行运算,多数实现上它们的效率仍低于用算术运算符乘或除以二的幂。
提供 scalbln 函数,因为从最小正浮点数放大到最大正有限值的因子可能大于标准保证的 INT_MAX 32767。特别是对于 80 位 long double,因子是 32828。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.13 The scalbn functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.13 The scalbn functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.13 The scalbn functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.13 The scalbn functions (第 460 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
| scalbn 的 C++ 文档 |
scalbnf
原址:https://zh.cppreference.com/w/c/numeric/math/scalbn
作用:高效计算一个数乘 FLT_RADIX 的幂 (函数)
备注:
| |
1-3,5-7) 将浮点数 arg 乘以 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4,8) 泛型宏:若 arg 拥有 long double 类型,则调用 scalbnl 或 scalblnl。否则,若 arg 拥有整数类型或 double 类型,则调用 scalbn 或 scalbln。否则调用 scalbnf 或 scalblnf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×FLT_RADIXexp
*)。
若出现上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),scalbn 等价于 ldexp。
尽管指定 scalbn 和 scalbln 高效进行运算,多数实现上它们的效率仍低于用算术运算符乘或除以二的幂。
提供 scalbln 函数,因为从最小正浮点数放大到最大正有限值的因子可能大于标准保证的 INT_MAX 32767。特别是对于 80 位 long double,因子是 32828。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.13 The scalbn functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.13 The scalbn functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.13 The scalbn functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.13 The scalbn functions (第 460 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
| scalbn 的 C++ 文档 |
scalbnl
原址:https://zh.cppreference.com/w/c/numeric/math/scalbn
作用:高效计算一个数乘 FLT_RADIX 的幂 (函数)
备注:
| |
1-3,5-7) 将浮点数 arg 乘以 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂。
4,8) 泛型宏:若 arg 拥有 long double 类型,则调用 scalbnl 或 scalblnl。否则,若 arg 拥有整数类型或 double 类型,则调用 scalbn 或 scalbln。否则调用 scalbnf 或 scalblnf。
参数
| arg | - | 浮点数 |
|---|---|---|
| exp | - | 整数 |
返回值
若不出现错误,则返回 arg 乘 FLT_RADIX 的 [exp](http://zh.cppreference.com/w/c/numeric/math/exp) 次幂(*arg×FLT_RADIXexp
*)。
若出现上溢所致的值域错误,则返回 ±[HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 决不引发 FE_INEXACT,除非出现值域错误(结果准确)
- 忽略当前舍入模式,除非出现值域错误
- 若
arg为 ±0,则返回不修改的参数 - 若
arg为 ±∞,则返回不修改的参数 - 若
[exp](http://zh.cppreference.com/w/c/numeric/math/exp)为 0,则返回不修改的arg - 若
arg为 NaN,则返回 NaN
注解
二进制系统上(其中 FLT_RADIX 为 2),scalbn 等价于 ldexp。
尽管指定 scalbn 和 scalbln 高效进行运算,多数实现上它们的效率仍低于用算术运算符乘或除以二的幂。
提供 scalbln 函数,因为从最小正浮点数放大到最大正有限值的因子可能大于标准保证的 INT_MAX 32767。特别是对于 80 位 long double,因子是 32828。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.6.13 The scalbn functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.3.13 The scalbn functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.6.13 The scalbn functions (第 247 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.3.13 The scalbn functions (第 523 页)
C99 标准(ISO/IEC 9899:1999):
7.12.6.13 The scalbn functions (第 228 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.3.13 The scalbn functions (第 460 页)
参阅
| frexp frexpf (C99) frexpl (C99) | 将数拆分成有效数字和 2 的幂次 (函数) |
|---|---|
| ldexp ldexpf (C99) ldexpl (C99) | 将数乘以 2 的幂 (函数) |
| scalbn 的 C++ 文档 |
sin
原址:https://zh.cppreference.com/w/c/numeric/math/sin
作用:计算正弦({\small\sin{x} }{\small\sin{x} }sin(x)) (函数)
备注:
| |
1-3) 计算 arg(以弧度度量)的正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 sinl。否则,若实参拥有整数类型或 double 类型,则调用 sin。否则调用 sinf 。若实参是复数,则该宏调用对应的复函数([csinf](http://zh.cppreference.com/w/c/numeric/complex/csin)、[csin](http://zh.cppreference.com/w/c/numeric/complex/csin)、[csinl](http://zh.cppreference.com/w/c/numeric/complex/csin))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不发生错误,则返回 arg 的正弦(sin(arg)),值域为 [-1 ; +1]。
若 arg 的绝对值很大,结果可能拥有少量或无有效数字。 (C99 前)
若发生定义域错误,则返回实现定义的值(受支持的平台上为 NaN )。
若发生下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数是 ±0,则返回未修改的实参
- 若参数是 ±∞,则返回 NaN 并引发 FE_INVALID
- 若参数是 NaN,则返回 NaN
注意
实参为无穷大的情况, C 中不指定为定义域错误,但它被指定为 POSIX 中的定义域错误。
POSIX 亦指定在溢出的情况下,返回不修改的 arg,而且若不支持如此,则返回实现定义的不大于 DBL_MIN、FLT_MIN 及 LDBL_MIN 的值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.6 The sin functions (第 TBD 页)
7.27 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.6 The sin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.6 The sin functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.6 The sin functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.6 The sin functions (第 239-240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.6 The sin functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.6 The sin functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.6 The sin functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.6 The sin function
参阅
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
|---|---|
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
| csin (C99) csinf (C99) csinl (C99) | 计算复数正弦 (函数) |
| sin 的 C++ 文档 |
sinf
原址:https://zh.cppreference.com/w/c/numeric/math/sin
作用:计算正弦({\small\sin{x} }{\small\sin{x} }sin(x)) (函数)
备注:
| |
1-3) 计算 arg(以弧度度量)的正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 sinl。否则,若实参拥有整数类型或 double 类型,则调用 sin。否则调用 sinf 。若实参是复数,则该宏调用对应的复函数([csinf](http://zh.cppreference.com/w/c/numeric/complex/csin)、[csin](http://zh.cppreference.com/w/c/numeric/complex/csin)、[csinl](http://zh.cppreference.com/w/c/numeric/complex/csin))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不发生错误,则返回 arg 的正弦(sin(arg)),值域为 [-1 ; +1]。
若 arg 的绝对值很大,结果可能拥有少量或无有效数字。 (C99 前)
若发生定义域错误,则返回实现定义的值(受支持的平台上为 NaN )。
若发生下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数是 ±0,则返回未修改的实参
- 若参数是 ±∞,则返回 NaN 并引发 FE_INVALID
- 若参数是 NaN,则返回 NaN
注意
实参为无穷大的情况, C 中不指定为定义域错误,但它被指定为 POSIX 中的定义域错误。
POSIX 亦指定在溢出的情况下,返回不修改的 arg,而且若不支持如此,则返回实现定义的不大于 DBL_MIN、FLT_MIN 及 LDBL_MIN 的值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.6 The sin functions (第 TBD 页)
7.27 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.6 The sin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.6 The sin functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.6 The sin functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.6 The sin functions (第 239-240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.6 The sin functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.6 The sin functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.6 The sin functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.6 The sin function
参阅
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
|---|---|
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
| csin (C99) csinf (C99) csinl (C99) | 计算复数正弦 (函数) |
| sin 的 C++ 文档 |
sinh
原址:https://zh.cppreference.com/w/c/numeric/math/sinh
作用:计算双曲正弦({\small\sinh{x} }{\small\sinh{x} }sinh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 sinhl。否则,若实参拥有整数类型或 double 类型,则调用 sinh。否则调用 sinhf。若实参为复数,则宏调用对应的复数函数([csinhf](http://zh.cppreference.com/w/c/numeric/complex/csinh)、[csinh](http://zh.cppreference.com/w/c/numeric/complex/csinh)、[csinhl](http://zh.cppreference.com/w/c/numeric/complex/csinh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲正弦(sinh(arg) 或
| earg -e-arg |
|---|
| 2 |
)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0 或 ±∞,则返回未修改的实参
- 若实参为 NaN,则返回 NaN
注解
POSIX 指定在下溢情况下,返回不修改的 arg,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.5 The sinh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.5 The sinh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.5 The sinh functions (第 176 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.5 The sinh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.5 The sinh functions (第 241-242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.5 The sinh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.5 The sinh functions (第 222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.5 The sinh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.2 The sinh function
参阅
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
|---|---|
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
| csinh (C99) csinhf (C99) csinhl (C99) | 计算复数双曲正弦 (函数) |
| sinh 的 C++ 文档 |
sinhf
原址:https://zh.cppreference.com/w/c/numeric/math/sinh
作用:计算双曲正弦({\small\sinh{x} }{\small\sinh{x} }sinh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 sinhl。否则,若实参拥有整数类型或 double 类型,则调用 sinh。否则调用 sinhf。若实参为复数,则宏调用对应的复数函数([csinhf](http://zh.cppreference.com/w/c/numeric/complex/csinh)、[csinh](http://zh.cppreference.com/w/c/numeric/complex/csinh)、[csinhl](http://zh.cppreference.com/w/c/numeric/complex/csinh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲正弦(sinh(arg) 或
| earg -e-arg |
|---|
| 2 |
)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0 或 ±∞,则返回未修改的实参
- 若实参为 NaN,则返回 NaN
注解
POSIX 指定在下溢情况下,返回不修改的 arg,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.5 The sinh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.5 The sinh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.5 The sinh functions (第 176 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.5 The sinh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.5 The sinh functions (第 241-242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.5 The sinh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.5 The sinh functions (第 222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.5 The sinh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.2 The sinh function
参阅
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
|---|---|
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
| csinh (C99) csinhf (C99) csinhl (C99) | 计算复数双曲正弦 (函数) |
| sinh 的 C++ 文档 |
sinhl
原址:https://zh.cppreference.com/w/c/numeric/math/sinh
作用:计算双曲正弦({\small\sinh{x} }{\small\sinh{x} }sinh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 sinhl。否则,若实参拥有整数类型或 double 类型,则调用 sinh。否则调用 sinhf。若实参为复数,则宏调用对应的复数函数([csinhf](http://zh.cppreference.com/w/c/numeric/complex/csinh)、[csinh](http://zh.cppreference.com/w/c/numeric/complex/csinh)、[csinhl](http://zh.cppreference.com/w/c/numeric/complex/csinh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲正弦(sinh(arg) 或
| earg -e-arg |
|---|
| 2 |
)。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参为 ±0 或 ±∞,则返回未修改的实参
- 若实参为 NaN,则返回 NaN
注解
POSIX 指定在下溢情况下,返回不修改的 arg,而若不支持如此,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.5 The sinh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.5 The sinh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.5 The sinh functions (第 176 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.2.5 The sinh functions (第 379 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.5 The sinh functions (第 241-242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.5 The sinh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.5 The sinh functions (第 222 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.5 The sinh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.2 The sinh function
参阅
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
|---|---|
| tanh tanhf (C99) tanhl (C99) | 计算双曲正切(tanhxtanhx) (函数) |
| asinh (C99) asinhf (C99) asinhl (C99) | 计算反双曲正弦(arsinhxarsinhx) (函数) |
| csinh (C99) csinhf (C99) csinhl (C99) | 计算复数双曲正弦 (函数) |
| sinh 的 C++ 文档 |
sinl
原址:https://zh.cppreference.com/w/c/numeric/math/sin
作用:计算正弦({\small\sin{x} }{\small\sin{x} }sin(x)) (函数)
备注:
| |
1-3) 计算 arg(以弧度度量)的正弦。
4) 泛型宏:若实参拥有 long double 类型,则调用 sinl。否则,若实参拥有整数类型或 double 类型,则调用 sin。否则调用 sinf 。若实参是复数,则该宏调用对应的复函数([csinf](http://zh.cppreference.com/w/c/numeric/complex/csin)、[csin](http://zh.cppreference.com/w/c/numeric/complex/csin)、[csinl](http://zh.cppreference.com/w/c/numeric/complex/csin))。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不发生错误,则返回 arg 的正弦(sin(arg)),值域为 [-1 ; +1]。
若 arg 的绝对值很大,结果可能拥有少量或无有效数字。 (C99 前)
若发生定义域错误,则返回实现定义的值(受支持的平台上为 NaN )。
若发生下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数是 ±0,则返回未修改的实参
- 若参数是 ±∞,则返回 NaN 并引发 FE_INVALID
- 若参数是 NaN,则返回 NaN
注意
实参为无穷大的情况, C 中不指定为定义域错误,但它被指定为 POSIX 中的定义域错误。
POSIX 亦指定在溢出的情况下,返回不修改的 arg,而且若不支持如此,则返回实现定义的不大于 DBL_MIN、FLT_MIN 及 LDBL_MIN 的值。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.6 The sin functions (第 TBD 页)
7.27 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.6 The sin functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.6 The sin functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.6 The sin functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.6 The sin functions (第 239-240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.6 The sin functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.6 The sin functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.6 The sin functions (第 456 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.6 The sin function
参阅
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
|---|---|
| tan tanf (C99) tanl (C99) | 计算正切(tanxtanx) (函数) |
| asin asinf (C99) asinl (C99) | 计算反正弦(arcsinxarcsinx) (函数) |
| csin (C99) csinf (C99) csinl (C99) | 计算复数正弦 (函数) |
| sin 的 C++ 文档 |
sqrt
原址:https://zh.cppreference.com/w/c/numeric/math/sqrt
作用:计算平方根(\small{\sqrt{x} }\small{\sqrt{x} }√x) (函数)
备注:
| |
1-3) 计算 arg 的平方根。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 sqrtl。否则,若 arg 拥有整数类型或 double 类型,则调用 sqrt。否则调用 sqrtf。若 arg 为复数或虚数,则宏调用对应复数函数([csqrtf](http://zh.cppreference.com/w/c/numeric/complex/csqrt)、[csqrt](http://zh.cppreference.com/w/c/numeric/complex/csqrt)、[csqrtl](http://zh.cppreference.com/w/c/numeric/complex/csqrt))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的平方根(√argarg)。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参小于 -0,则引发 FE_INVALID 并返回 NaN。
- 若实参为 +∞ 或 ±0,则返回不修改的参数。
- 若实参为 NaN,则返回 NaN。
注解
IEEE 标准要求 sqrt 为准确。其他要求为准确的运算只有算术运算符和函数 fma。舍入到返回类型后(用默认舍入模式),sqrt 的结果与无限精度结果不可辨别。换言之,误差小于 0.5 ulp。其他函数,含 pow,不受这种制约。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.5 The sqrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.5 The sqrt functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.5 The sqrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.5 The sqrt functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.5 The sqrt functions (第 249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.5 The sqrt functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.5 The sqrt functions (第 229-230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.5 The sqrt functions (第 462 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.5.2 The sqrt function
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| csqrt (C99) csqrtf (C99) csqrtl (C99) | 计算复数平方根 (函数) |
| sqrt 的 C++ 文档 |
sqrtf
原址:https://zh.cppreference.com/w/c/numeric/math/sqrt
作用:计算平方根(\small{\sqrt{x} }\small{\sqrt{x} }√x) (函数)
备注:
| |
1-3) 计算 arg 的平方根。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 sqrtl。否则,若 arg 拥有整数类型或 double 类型,则调用 sqrt。否则调用 sqrtf。若 arg 为复数或虚数,则宏调用对应复数函数([csqrtf](http://zh.cppreference.com/w/c/numeric/complex/csqrt)、[csqrt](http://zh.cppreference.com/w/c/numeric/complex/csqrt)、[csqrtl](http://zh.cppreference.com/w/c/numeric/complex/csqrt))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的平方根(√argarg)。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参小于 -0,则引发 FE_INVALID 并返回 NaN。
- 若实参为 +∞ 或 ±0,则返回不修改的参数。
- 若实参为 NaN,则返回 NaN。
注解
IEEE 标准要求 sqrt 为准确。其他要求为准确的运算只有算术运算符和函数 fma。舍入到返回类型后(用默认舍入模式),sqrt 的结果与无限精度结果不可辨别。换言之,误差小于 0.5 ulp。其他函数,含 pow,不受这种制约。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.5 The sqrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.5 The sqrt functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.5 The sqrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.5 The sqrt functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.5 The sqrt functions (第 249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.5 The sqrt functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.5 The sqrt functions (第 229-230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.5 The sqrt functions (第 462 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.5.2 The sqrt function
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| csqrt (C99) csqrtf (C99) csqrtl (C99) | 计算复数平方根 (函数) |
| sqrt 的 C++ 文档 |
sqrtl
原址:https://zh.cppreference.com/w/c/numeric/math/sqrt
作用:计算平方根(\small{\sqrt{x} }\small{\sqrt{x} }√x) (函数)
备注:
| |
1-3) 计算 arg 的平方根。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 sqrtl。否则,若 arg 拥有整数类型或 double 类型,则调用 sqrt。否则调用 sqrtf。若 arg 为复数或虚数,则宏调用对应复数函数([csqrtf](http://zh.cppreference.com/w/c/numeric/complex/csqrt)、[csqrt](http://zh.cppreference.com/w/c/numeric/complex/csqrt)、[csqrtl](http://zh.cppreference.com/w/c/numeric/complex/csqrt))。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的平方根(√argarg)。
若出现定义域错误,则返回实现定义值(支持的平台上为 NaN)。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若 arg 小于零则出现定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若实参小于 -0,则引发 FE_INVALID 并返回 NaN。
- 若实参为 +∞ 或 ±0,则返回不修改的参数。
- 若实参为 NaN,则返回 NaN。
注解
IEEE 标准要求 sqrt 为准确。其他要求为准确的运算只有算术运算符和函数 fma。舍入到返回类型后(用默认舍入模式),sqrt 的结果与无限精度结果不可辨别。换言之,误差小于 0.5 ulp。其他函数,含 pow,不受这种制约。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.7.5 The sqrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.5 The sqrt functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.7.5 The sqrt functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.4.5 The sqrt functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.7.5 The sqrt functions (第 249 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.4.5 The sqrt functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.7.5 The sqrt functions (第 229-230 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.4.5 The sqrt functions (第 462 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.5.2 The sqrt function
参阅
| pow powf (C99) powl (C99) | 计算一个数的给定次幂(xyxy) (函数) |
|---|---|
| cbrt (C99) cbrtf (C99) cbrtl (C99) | 计算立方根(3√xx3) (函数) |
| hypot (C99) hypotf (C99) hypotl (C99) | 计算两个给定数平方和的平方根(√x2+y2x2+y2) (函数) |
| csqrt (C99) csqrtf (C99) csqrtl (C99) | 计算复数平方根 (函数) |
| sqrt 的 C++ 文档 |
tan
原址:https://zh.cppreference.com/w/c/numeric/math/tan
作用:计算正切({\small\tan{x} }{\small\tan{x} }tan(x)) (函数)
备注:
| |
1-6) 计算 arg(以弧度度量)的正切。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3)(tanl)。否则,若实参拥有整数类型或 double 类型,则调用 (2)(tan)。否则调用 (1)(tanf)。若实参为复数,则宏调用对应的复数函数(ctanf、ctan、ctanl)。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的正切(tan(arg))。
若 arg 的绝对值很大,则结果可能有较少或无有效数字。 (C99 前)
若出现定义域错误,则返回实现定义值(受支持平台为 NaN)。
若发生下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算数(IEC 60559),则
- 若实参为 ±0,则返回不修改的参数
- 若实参为 ±∞,则返回 NaN 并引发 FE_INVALID
- 若实参为 NaN,则返回 NaN
注意
实参为无限大的情况,在 C 中未被指定为定义域错误,但它被定义为 POSIX 中的定义域错误。
函数在 π(1/2 + n) 有数学上的极点;然而无常用浮点数表示能准确表示 π/2,故而没有值使得极点错误出现。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.7 The tan functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.7 The tan functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.7 The tan functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.7 The tan functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.7 The tan functions (第 240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.7 The tan functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.7 The tan functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.7 The tan functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.7 The tan function
参阅
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
|---|---|
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| ctan (C99) ctanf (C99) ctanl (C99) | 计算复数正切 (函数) |
| tan 的 C++ 文档 |
tanf
原址:https://zh.cppreference.com/w/c/numeric/math/tan
作用:计算正切({\small\tan{x} }{\small\tan{x} }tan(x)) (函数)
备注:
| |
1-6) 计算 arg(以弧度度量)的正切。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3)(tanl)。否则,若实参拥有整数类型或 double 类型,则调用 (2)(tan)。否则调用 (1)(tanf)。若实参为复数,则宏调用对应的复数函数(ctanf、ctan、ctanl)。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的正切(tan(arg))。
若 arg 的绝对值很大,则结果可能有较少或无有效数字。 (C99 前)
若出现定义域错误,则返回实现定义值(受支持平台为 NaN)。
若发生下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算数(IEC 60559),则
- 若实参为 ±0,则返回不修改的参数
- 若实参为 ±∞,则返回 NaN 并引发 FE_INVALID
- 若实参为 NaN,则返回 NaN
注意
实参为无限大的情况,在 C 中未被指定为定义域错误,但它被定义为 POSIX 中的定义域错误。
函数在 π(1/2 + n) 有数学上的极点;然而无常用浮点数表示能准确表示 π/2,故而没有值使得极点错误出现。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.7 The tan functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.7 The tan functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.7 The tan functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.7 The tan functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.7 The tan functions (第 240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.7 The tan functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.7 The tan functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.7 The tan functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.7 The tan function
参阅
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
|---|---|
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| ctan (C99) ctanf (C99) ctanl (C99) | 计算复数正切 (函数) |
| tan 的 C++ 文档 |
tanh
原址:https://zh.cppreference.com/w/c/numeric/math/tanh
作用:计算双曲正切({\small\tanh{x} }{\small\tanh{x} }tanh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲正切。
4) 泛型宏:若实参拥有 long double 类型,则调用 tanhl。否则,若实参拥有整数类型或 double 类型,则调用 tanh。否则调用 tanhf 若实参为复数,则宏调用对应的复数函数([ctanhf](http://zh.cppreference.com/w/c/numeric/complex/ctanh)、[ctanh](http://zh.cppreference.com/w/c/numeric/complex/ctanh)、[ctanhl](http://zh.cppreference.com/w/c/numeric/complex/ctanh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲正切(tanh(arg) 或
| earg -e-arg |
|---|
| earg +e-arg |
)。
若发生下溢所致的错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±0
- 若参数为 ±∞,则返回 ±1
- 若参数为 NaN,则返回 NaN
注解
POSIX 指定在下溢的情况中,返回不修改的 arg,而且若不支持这么做,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.6 The tanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.6 The tanh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.6 The tanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.6 The tanh functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.6 The tanh functions (第 242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.6 The tanh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.6 The tanh functions (第 222-223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.6 The tanh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.3 The tanh function
参阅
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
|---|---|
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| ctanh (C99) ctanhf (C99) ctanhl (C99) | 计算复数双曲正切 (函数) |
| tanh 的 C++ 文档 |
tanhf
原址:https://zh.cppreference.com/w/c/numeric/math/tanh
作用:计算双曲正切({\small\tanh{x} }{\small\tanh{x} }tanh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲正切。
4) 泛型宏:若实参拥有 long double 类型,则调用 tanhl。否则,若实参拥有整数类型或 double 类型,则调用 tanh。否则调用 tanhf 若实参为复数,则宏调用对应的复数函数([ctanhf](http://zh.cppreference.com/w/c/numeric/complex/ctanh)、[ctanh](http://zh.cppreference.com/w/c/numeric/complex/ctanh)、[ctanhl](http://zh.cppreference.com/w/c/numeric/complex/ctanh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲正切(tanh(arg) 或
| earg -e-arg |
|---|
| earg +e-arg |
)。
若发生下溢所致的错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±0
- 若参数为 ±∞,则返回 ±1
- 若参数为 NaN,则返回 NaN
注解
POSIX 指定在下溢的情况中,返回不修改的 arg,而且若不支持这么做,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.6 The tanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.6 The tanh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.6 The tanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.6 The tanh functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.6 The tanh functions (第 242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.6 The tanh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.6 The tanh functions (第 222-223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.6 The tanh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.3 The tanh function
参阅
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
|---|---|
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| ctanh (C99) ctanhf (C99) ctanhl (C99) | 计算复数双曲正切 (函数) |
| tanh 的 C++ 文档 |
tanhl
原址:https://zh.cppreference.com/w/c/numeric/math/tanh
作用:计算双曲正切({\small\tanh{x} }{\small\tanh{x} }tanh(x)) (函数)
备注:
| |
1-3) 计算 arg 的双曲正切。
4) 泛型宏:若实参拥有 long double 类型,则调用 tanhl。否则,若实参拥有整数类型或 double 类型,则调用 tanh。否则调用 tanhf 若实参为复数,则宏调用对应的复数函数([ctanhf](http://zh.cppreference.com/w/c/numeric/complex/ctanh)、[ctanh](http://zh.cppreference.com/w/c/numeric/complex/ctanh)、[ctanhl](http://zh.cppreference.com/w/c/numeric/complex/ctanh))。
参数
| arg | - | 表示双曲角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的双曲正切(tanh(arg) 或
| earg -e-arg |
|---|
| earg +e-arg |
)。
若发生下溢所致的错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±0
- 若参数为 ±∞,则返回 ±1
- 若参数为 NaN,则返回 NaN
注解
POSIX 指定在下溢的情况中,返回不修改的 arg,而且若不支持这么做,则返回不大于 DBL_MIN、FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
| |
输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.5.6 The tanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.6 The tanh functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.5.6 The tanh functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.2.6 The tanh functions (第 TBD 页)
C11 标准(ISO/IEC 9899:2011):
7.12.5.6 The tanh functions (第 242 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.2.6 The tanh functions (第 520 页)
C99 标准(ISO/IEC 9899:1999):
7.12.5.6 The tanh functions (第 222-223 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.2.6 The tanh functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.3.3 The tanh function
参阅
| sinh sinhf (C99) sinhl (C99) | 计算双曲正弦(sinhxsinhx) (函数) |
|---|---|
| cosh coshf (C99) coshl (C99) | 计算双曲余弦(coshxcoshx) (函数) |
| atanh (C99) atanhf (C99) atanhl (C99) | 计算反双曲正切(artanhxartanhx) (函数) |
| ctanh (C99) ctanhf (C99) ctanhl (C99) | 计算复数双曲正切 (函数) |
| tanh 的 C++ 文档 |
tanl
原址:https://zh.cppreference.com/w/c/numeric/math/tan
作用:计算正切({\small\tan{x} }{\small\tan{x} }tan(x)) (函数)
备注:
| |
1-6) 计算 arg(以弧度度量)的正切。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3)(tanl)。否则,若实参拥有整数类型或 double 类型,则调用 (2)(tan)。否则调用 (1)(tanf)。若实参为复数,则宏调用对应的复数函数(ctanf、ctan、ctanl)。
仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)。 (C23 起)
参数
| arg | - | 以弧度表示角的浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的正切(tan(arg))。
若 arg 的绝对值很大,则结果可能有较少或无有效数字。 (C99 前)
若出现定义域错误,则返回实现定义值(受支持平台为 NaN)。
若发生下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算数(IEC 60559),则
- 若实参为 ±0,则返回不修改的参数
- 若实参为 ±∞,则返回 NaN 并引发 FE_INVALID
- 若实参为 NaN,则返回 NaN
注意
实参为无限大的情况,在 C 中未被指定为定义域错误,但它被定义为 POSIX 中的定义域错误。
函数在 π(1/2 + n) 有数学上的极点;然而无常用浮点数表示能准确表示 π/2,故而没有值使得极点错误出现。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.4.7 The tan functions (第 TBD 页)
7.25 Type-generic math <tgmath.h> (第 TBD 页)
F.10.1.7 The tan functions (第 TBD 页)
C17 标准(ISO/IEC 9899:2018):
7.12.4.7 The tan functions (第 175 页)
7.25 Type-generic math <tgmath.h> (第 272-273 页)
F.10.1.7 The tan functions (第 378 页)
C11 标准(ISO/IEC 9899:2011):
7.12.4.7 The tan functions (第 240 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.1.7 The tan functions (第 519 页)
C99 标准(ISO/IEC 9899:1999):
7.12.4.7 The tan functions (第 220 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.1.7 The tan functions (第 457 页)
C89/C90 标准(ISO/IEC 9899:1990):
- 4.5.2.7 The tan function
参阅
| sin sinf (C99) sinl (C99) | 计算正弦(sinxsinx) (函数) |
|---|---|
| cos cosf (C99) cosl (C99) | 计算余弦(cosxcosx) (函数) |
| atan atanf (C99) atanl (C99) | 计算反正切(arctanxarctanx) (函数) |
| ctan (C99) ctanf (C99) ctanl (C99) | 计算复数正切 (函数) |
| tan 的 C++ 文档 |
tgamma
原址:https://zh.cppreference.com/w/c/numeric/math/tgamma
作用:计算伽马函数 (函数)
备注:
| |
1-3) 计算 arg 的伽马函数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 tgammal。否则,若 arg 拥有整数类型或 double 类型,则调用 tgamma。否则调用 tgammaf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的 Γ 函数值,即 Γ(arg)=∫∞0targ−1e−tdtΓ(arg)=∫0∞targ−1e−tdt。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现极点错误,则返回 [HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若 arg 为零或为小于零的整数,则可能出现极点或定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±∞ 并引发 FE_DIVBYZERO
- 若参数为负整数,则返回 NaN 并引发 FE_INVALID
- 若参数为 -∞,则返回 NaN 并引发 FE_INVALID
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注解
若 arg 为自然数,则 tgamma(arg) 为 arg-1 的阶乘。许多实现若参数是足够小的整数,则计算准确的整数域阶乘。
对于 IEEE 兼容的 double 类型,若 0 < x < 1/DBL_MAX 或 x > 171.7 则发生上溢。
POSIX 要求若实参为零则出现极点错误,但在实参为负整数时出现定义域错误。它亦指定在将来,对于负整数,定义域错误可能被替换成浮点数错误(这些情况下返回值将从 NaN 更改为 ±∞)。
多数实现中有名为 gamma 的非标准函数,但其定义不一致。例如,gamma 的 glibc 和 4.2BSD 版本执行 lgamma,但 gamma 的 4.4BSD 版本执行 tgamma。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.4 The tgamma functions (第 231 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.4 The tgamma functions (第 462 页)
参阅
| lgamma (C99) lgammaf (C99) lgammal (C99) | 计算伽马函数的自然对数(底为 e) (函数) |
|---|---|
| tgamma 的 C++ 文档 |
外部链接
Weisstein, Eric W. “伽马函数”来自 MathWorld–A Wolfram Web Resource。
tgammaf
原址:https://zh.cppreference.com/w/c/numeric/math/tgamma
作用:计算伽马函数 (函数)
备注:
| |
1-3) 计算 arg 的伽马函数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 tgammal。否则,若 arg 拥有整数类型或 double 类型,则调用 tgamma。否则调用 tgammaf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的 Γ 函数值,即 Γ(arg)=∫∞0targ−1e−tdtΓ(arg)=∫0∞targ−1e−tdt。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现极点错误,则返回 [HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若 arg 为零或为小于零的整数,则可能出现极点或定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±∞ 并引发 FE_DIVBYZERO
- 若参数为负整数,则返回 NaN 并引发 FE_INVALID
- 若参数为 -∞,则返回 NaN 并引发 FE_INVALID
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注解
若 arg 为自然数,则 tgamma(arg) 为 arg-1 的阶乘。许多实现若参数是足够小的整数,则计算准确的整数域阶乘。
对于 IEEE 兼容的 double 类型,若 0 < x < 1/DBL_MAX 或 x > 171.7 则发生上溢。
POSIX 要求若实参为零则出现极点错误,但在实参为负整数时出现定义域错误。它亦指定在将来,对于负整数,定义域错误可能被替换成浮点数错误(这些情况下返回值将从 NaN 更改为 ±∞)。
多数实现中有名为 gamma 的非标准函数,但其定义不一致。例如,gamma 的 glibc 和 4.2BSD 版本执行 lgamma,但 gamma 的 4.4BSD 版本执行 tgamma。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.4 The tgamma functions (第 231 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.4 The tgamma functions (第 462 页)
参阅
| lgamma (C99) lgammaf (C99) lgammal (C99) | 计算伽马函数的自然对数(底为 e) (函数) |
|---|---|
| tgamma 的 C++ 文档 |
外部链接
Weisstein, Eric W. “伽马函数”来自 MathWorld–A Wolfram Web Resource。
tgammal
原址:https://zh.cppreference.com/w/c/numeric/math/tgamma
作用:计算伽马函数 (函数)
备注:
| |
1-3) 计算 arg 的伽马函数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 tgammal。否则,若 arg 拥有整数类型或 double 类型,则调用 tgamma。否则调用 tgammaf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不出现错误,则返回 arg 的 Γ 函数值,即 Γ(arg)=∫∞0targ−1e−tdtΓ(arg)=∫0∞targ−1e−tdt。
若出现定义域错误,则返回实现定义值(受支持平台上为 NaN)。
若出现极点错误,则返回 [HUGE_VAL](http://zh.cppreference.com/w/c/numeric/math/HUGE_VAL)、±HUGE_VALF 或 ±HUGE_VALL。
若出现上溢所致的值域错误,则返回 ±HUGE_VAL、±HUGE_VALF 或 ±HUGE_VALL。
若出现下溢所致的值域错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误
若 arg 为零或为小于零的整数,则可能出现极点或定义域错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 若参数为 ±0,则返回 ±∞ 并引发 FE_DIVBYZERO
- 若参数为负整数,则返回 NaN 并引发 FE_INVALID
- 若参数为 -∞,则返回 NaN 并引发 FE_INVALID
- 若参数为 +∞,则返回 +∞
- 若参数为 NaN,则返回 NaN
注解
若 arg 为自然数,则 tgamma(arg) 为 arg-1 的阶乘。许多实现若参数是足够小的整数,则计算准确的整数域阶乘。
对于 IEEE 兼容的 double 类型,若 0 < x < 1/DBL_MAX 或 x > 171.7 则发生上溢。
POSIX 要求若实参为零则出现极点错误,但在实参为负整数时出现定义域错误。它亦指定在将来,对于负整数,定义域错误可能被替换成浮点数错误(这些情况下返回值将从 NaN 更改为 ±∞)。
多数实现中有名为 gamma 的非标准函数,但其定义不一致。例如,gamma 的 glibc 和 4.2BSD 版本执行 lgamma,但 gamma 的 4.4BSD 版本执行 tgamma。
示例
| |
可能的输出:
| |
引用
C23 标准(ISO/IEC 9899:2024):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C17 标准(ISO/IEC 9899:2018):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C11 标准(ISO/IEC 9899:2011):
7.12.8.4 The tgamma functions (第 250 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.5.4 The tgamma functions (第 525 页)
C99 标准(ISO/IEC 9899:1999):
7.12.8.4 The tgamma functions (第 231 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.5.4 The tgamma functions (第 462 页)
参阅
| lgamma (C99) lgammaf (C99) lgammal (C99) | 计算伽马函数的自然对数(底为 e) (函数) |
|---|---|
| tgamma 的 C++ 文档 |
外部链接
Weisstein, Eric W. “伽马函数”来自 MathWorld–A Wolfram Web Resource。
trunc
原址:https://zh.cppreference.com/w/c/numeric/math/trunc
作用:取整到绝对值不大于给定值的最接近整数 (函数)
备注:
| |
1-3) 计算绝对值不大于 arg 的最接近整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 truncl。否则,若 arg 拥有整数类型或 double 类型,则调用 trunc。否则,调用 truncf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不发生错误,则返回绝对值不大于 arg 的最接近整数(换言之,将 arg 向零舍入)。
返回值
参数
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的实参。 - 若
arg为 ±0,则返回未修改的实参。 - 若 arg 为 NaN,则返回 NaN
注意
截断非整数有限值时可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故此函数自身决不上溢;然而存储结果于整数对象时,结果可以溢出任何整数类型(包含 intmax_t)。
从浮点数到整数类型的隐式转换始终向零舍入,但它被限制于能表示成目标类型的值。
示例
| |
可能的输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
7.12.9.8 The trunc functions (第 253-254 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.8 The trunc functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.8 The trunc functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.8 The trunc functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| trunc 的 C++ 文档 |
truncf
原址:https://zh.cppreference.com/w/c/numeric/math/trunc
作用:取整到绝对值不大于给定值的最接近整数 (函数)
备注:
| |
1-3) 计算绝对值不大于 arg 的最接近整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 truncl。否则,若 arg 拥有整数类型或 double 类型,则调用 trunc。否则,调用 truncf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不发生错误,则返回绝对值不大于 arg 的最接近整数(换言之,将 arg 向零舍入)。
返回值
参数
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的实参。 - 若
arg为 ±0,则返回未修改的实参。 - 若 arg 为 NaN,则返回 NaN
注意
截断非整数有限值时可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故此函数自身决不上溢;然而存储结果于整数对象时,结果可以溢出任何整数类型(包含 intmax_t)。
从浮点数到整数类型的隐式转换始终向零舍入,但它被限制于能表示成目标类型的值。
示例
| |
可能的输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
7.12.9.8 The trunc functions (第 253-254 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.8 The trunc functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.8 The trunc functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.8 The trunc functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| trunc 的 C++ 文档 |
truncl
原址:https://zh.cppreference.com/w/c/numeric/math/trunc
作用:取整到绝对值不大于给定值的最接近整数 (函数)
备注:
| |
1-3) 计算绝对值不大于 arg 的最接近整数。
4) 泛型宏:若 arg 拥有 long double 类型,则调用 truncl。否则,若 arg 拥有整数类型或 double 类型,则调用 trunc。否则,调用 truncf。
参数
| arg | - | 浮点数 |
|---|---|---|
返回值
若不发生错误,则返回绝对值不大于 arg 的最接近整数(换言之,将 arg 向零舍入)。
返回值
参数
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点数算术(IEC 60559),则
- 当前舍入模式无效。
- 若
arg为 ±∞,则返回未修改的实参。 - 若
arg为 ±0,则返回未修改的实参。 - 若 arg 为 NaN,则返回 NaN
注意
截断非整数有限值时可以(但不要求)引发 FE_INEXACT。
所有标准浮点数格式中,最大可表示浮点数均为准确的整数,故此函数自身决不上溢;然而存储结果于整数对象时,结果可以溢出任何整数类型(包含 intmax_t)。
从浮点数到整数类型的隐式转换始终向零舍入,但它被限制于能表示成目标类型的值。
示例
| |
可能的输出:
| |
引用
C11 标准(ISO/IEC 9899:2011):
7.12.9.8 The trunc functions (第 253-254 页)
7.25 Type-generic math <tgmath.h> (第 373-375 页)
F.10.6.8 The trunc functions (第 528 页)
C99 标准(ISO/IEC 9899:1999):
7.12.9.8 The trunc functions (第 234 页)
7.22 Type-generic math <tgmath.h> (第 335-337 页)
F.9.6.8 The trunc functions (第 464 页)
参阅
| floor floorf (C99) floorl (C99) | 计算不大于给定值的最大整数 (函数) |
|---|---|
| ceil ceilf (C99) ceill (C99) | 计算不小于给定值的最小整数 (函数) |
| round (C99) roundf (C99) roundl (C99) lround (C99) lroundf (C99) lroundl (C99) llround (C99) llroundf (C99) llroundl (C99) | 取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |
| trunc 的 C++ 文档 |